annotate mmf.c @ 2627:af403e794831 libavformat

set a default value for num_channels
author aurel
date Thu, 18 Oct 2007 21:56:44 +0000
parents 213268d7594e
children d52c718e83f9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
1 /*
818
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
2 * Yamaha SMAF format
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
3 * Copyright (c) 2005 Vidar Madsen
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
4 *
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1172
diff changeset
5 * This file is part of FFmpeg.
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1172
diff changeset
6 *
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1172
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
818
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1172
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
818
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
11 *
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1172
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
818
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
15 * Lesser General Public License for more details.
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
16 *
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1172
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
896
edbe5c3717f9 Update licensing information: The FSF changed postal address.
diego
parents: 885
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
818
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
20 */
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
21 #include "avformat.h"
2545
213268d7594e move unrelated functions declarations out of allformats.h
aurel
parents: 2274
diff changeset
22 #include "raw.h"
1172
6a5e58d2114b move common stuff from avienc.c and wav.c to new file riff.c
mru
parents: 1169
diff changeset
23 #include "riff.h"
818
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
24
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
25 typedef struct {
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
26 offset_t atrpos, atsqpos, awapos;
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
27 offset_t data_size;
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
28 } MMFContext;
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
29
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
30 static int mmf_rates[] = { 4000, 8000, 11025, 22050, 44100 };
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
31
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
32 static int mmf_rate_code(int rate)
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
33 {
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
34 int i;
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
35 for(i = 0; i < 5; i++)
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
36 if(mmf_rates[i] == rate)
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
37 return i;
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
38 return -1;
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
39 }
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
40
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
41 static int mmf_rate(int code)
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
42 {
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
43 if((code < 0) || (code > 4))
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
44 return -1;
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
45 return mmf_rates[code];
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
46 }
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
47
902
5d1bcf01ce28 Properly #ifdef muxer-specific parts.
diego
parents: 896
diff changeset
48 #ifdef CONFIG_MUXERS
818
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
49 /* Copy of end_tag() from avienc.c, but for big-endian chunk size */
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
50 static void end_tag_be(ByteIOContext *pb, offset_t start)
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
51 {
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
52 offset_t pos;
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
53
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
54 pos = url_ftell(pb);
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
55 url_fseek(pb, start - 4, SEEK_SET);
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
56 put_be32(pb, (uint32_t)(pos - start));
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
57 url_fseek(pb, pos, SEEK_SET);
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
58 }
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
59
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
60 static int mmf_write_header(AVFormatContext *s)
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
61 {
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
62 MMFContext *mmf = s->priv_data;
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
63 ByteIOContext *pb = &s->pb;
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
64 offset_t pos;
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
65 int rate;
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
66
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 818
diff changeset
67 rate = mmf_rate_code(s->streams[0]->codec->sample_rate);
818
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
68 if(rate < 0) {
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 818
diff changeset
69 av_log(s, AV_LOG_ERROR, "Unsupported sample rate %d\n", s->streams[0]->codec->sample_rate);
818
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
70 return -1;
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
71 }
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
72
818
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
73 put_tag(pb, "MMMD");
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
74 put_be32(pb, 0);
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
75 pos = start_tag(pb, "CNTI");
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
76 put_byte(pb, 0); /* class */
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
77 put_byte(pb, 0); /* type */
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
78 put_byte(pb, 0); /* code type */
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
79 put_byte(pb, 0); /* status */
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
80 put_byte(pb, 0); /* counts */
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
81 put_tag(pb, "VN:libavcodec,"); /* metadata ("ST:songtitle,VN:version,...") */
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
82 end_tag_be(pb, pos);
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
83
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
84 put_buffer(pb, "ATR\x00", 4);
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
85 put_be32(pb, 0);
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
86 mmf->atrpos = url_ftell(pb);
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
87 put_byte(pb, 0); /* format type */
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
88 put_byte(pb, 0); /* sequence type */
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
89 put_byte(pb, (0 << 7) | (1 << 4) | rate); /* (channel << 7) | (format << 4) | rate */
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
90 put_byte(pb, 0); /* wave base bit */
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
91 put_byte(pb, 2); /* time base d */
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
92 put_byte(pb, 2); /* time base g */
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
93
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
94 put_tag(pb, "Atsq");
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
95 put_be32(pb, 16);
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
96 mmf->atsqpos = url_ftell(pb);
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
97 /* Will be filled on close */
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
98 put_buffer(pb, "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 16);
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
99
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
100 mmf->awapos = start_tag(pb, "Awa\x01");
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
101
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 818
diff changeset
102 av_set_pts_info(s->streams[0], 64, 1, s->streams[0]->codec->sample_rate);
818
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
103
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
104 put_flush_packet(pb);
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
105
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
106 return 0;
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
107 }
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
108
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
109 static int mmf_write_packet(AVFormatContext *s, AVPacket *pkt)
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
110 {
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
111 ByteIOContext *pb = &s->pb;
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
112 put_buffer(pb, pkt->data, pkt->size);
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
113 return 0;
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
114 }
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
115
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
116 /* Write a variable-length symbol */
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
117 static void put_varlength(ByteIOContext *pb, int val)
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
118 {
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
119 if(val < 128)
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
120 put_byte(pb, val);
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
121 else {
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
122 val -= 128;
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
123 put_byte(pb, 0x80 | val >> 7);
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
124 put_byte(pb, 0x7f & val);
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
125 }
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
126 }
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
127
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
128 static int mmf_write_trailer(AVFormatContext *s)
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
129 {
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
130 ByteIOContext *pb = &s->pb;
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
131 MMFContext *mmf = s->priv_data;
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
132 offset_t pos, size;
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
133 int gatetime;
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
134
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
135 if (!url_is_streamed(&s->pb)) {
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
136 /* Fill in length fields */
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
137 end_tag_be(pb, mmf->awapos);
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
138 end_tag_be(pb, mmf->atrpos);
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
139 end_tag_be(pb, 8);
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
140
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
141 pos = url_ftell(pb);
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
142 size = pos - mmf->awapos;
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
143
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
144 /* Fill Atsq chunk */
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
145 url_fseek(pb, mmf->atsqpos, SEEK_SET);
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
146
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
147 /* "play wav" */
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
148 put_byte(pb, 0); /* start time */
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
149 put_byte(pb, 1); /* (channel << 6) | wavenum */
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 818
diff changeset
150 gatetime = size * 500 / s->streams[0]->codec->sample_rate;
818
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
151 put_varlength(pb, gatetime); /* duration */
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
152
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
153 /* "nop" */
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
154 put_varlength(pb, gatetime); /* start time */
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
155 put_buffer(pb, "\xff\x00", 2); /* nop */
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
156
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
157 /* "end of sequence" */
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
158 put_buffer(pb, "\x00\x00\x00\x00", 4);
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
159
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
160 url_fseek(pb, pos, SEEK_SET);
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
161
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
162 put_flush_packet(pb);
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
163 }
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
164 return 0;
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
165 }
858
66cc656ea404 Replace CONFIG_ENCODERS/CONFIG_DECODERS with CONFIG_MUXERS/CONFIG_DEMUXERS
diego
parents: 856
diff changeset
166 #endif //CONFIG_MUXERS
818
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
167
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
168 static int mmf_probe(AVProbeData *p)
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
169 {
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
170 /* check file header */
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
171 if (p->buf[0] == 'M' && p->buf[1] == 'M' &&
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
172 p->buf[2] == 'M' && p->buf[3] == 'D' &&
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
173 p->buf[8] == 'C' && p->buf[9] == 'N' &&
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
174 p->buf[10] == 'T' && p->buf[11] == 'I')
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
175 return AVPROBE_SCORE_MAX;
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
176 else
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
177 return 0;
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
178 }
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
179
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
180 /* mmf input */
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
181 static int mmf_read_header(AVFormatContext *s,
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
182 AVFormatParameters *ap)
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
183 {
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
184 MMFContext *mmf = s->priv_data;
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
185 unsigned int tag;
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
186 ByteIOContext *pb = &s->pb;
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
187 AVStream *st;
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
188 offset_t file_size, size;
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
189 int rate, params;
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
190
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
191 tag = get_le32(pb);
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
192 if (tag != MKTAG('M', 'M', 'M', 'D'))
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
193 return -1;
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
194 file_size = get_be32(pb);
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
195
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
196 /* Skip some unused chunks that may or may not be present */
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
197 for(;; url_fseek(pb, size, SEEK_CUR)) {
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
198 tag = get_le32(pb);
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
199 size = get_be32(pb);
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
200 if(tag == MKTAG('C','N','T','I')) continue;
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
201 if(tag == MKTAG('O','P','D','A')) continue;
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
202 break;
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
203 }
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
204
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
205 /* Tag = "ATRx", where "x" = track number */
1065
fab79efcd476 report to user if mmf with midi found (and not supported)
alex
parents: 902
diff changeset
206 if ((tag & 0xffffff) == MKTAG('M', 'T', 'R', 0)) {
fab79efcd476 report to user if mmf with midi found (and not supported)
alex
parents: 902
diff changeset
207 av_log(s, AV_LOG_ERROR, "MIDI like format found, unsupported\n");
fab79efcd476 report to user if mmf with midi found (and not supported)
alex
parents: 902
diff changeset
208 return -1;
fab79efcd476 report to user if mmf with midi found (and not supported)
alex
parents: 902
diff changeset
209 }
818
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
210 if ((tag & 0xffffff) != MKTAG('A', 'T', 'R', 0)) {
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
211 av_log(s, AV_LOG_ERROR, "Unsupported SMAF chunk %08x\n", tag);
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
212 return -1;
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
213 }
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
214
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
215 get_byte(pb); /* format type */
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
216 get_byte(pb); /* sequence type */
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
217 params = get_byte(pb); /* (channel << 7) | (format << 4) | rate */
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
218 rate = mmf_rate(params & 0x0f);
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
219 if(rate < 0) {
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
220 av_log(s, AV_LOG_ERROR, "Invalid sample rate\n");
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
221 return -1;
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
222 }
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
223 get_byte(pb); /* wave base bit */
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
224 get_byte(pb); /* time base d */
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
225 get_byte(pb); /* time base g */
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
226
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
227 /* Skip some unused chunks that may or may not be present */
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
228 for(;; url_fseek(pb, size, SEEK_CUR)) {
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
229 tag = get_le32(pb);
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
230 size = get_be32(pb);
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
231 if(tag == MKTAG('A','t','s','q')) continue;
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
232 if(tag == MKTAG('A','s','p','I')) continue;
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
233 break;
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
234 }
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
235
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
236 /* Make sure it's followed by an Awa chunk, aka wave data */
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
237 if ((tag & 0xffffff) != MKTAG('A', 'w', 'a', 0)) {
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
238 av_log(s, AV_LOG_ERROR, "Unexpected SMAF chunk %08x\n", tag);
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
239 return -1;
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
240 }
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
241 mmf->data_size = size;
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
242
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
243 st = av_new_stream(s, 0);
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
244 if (!st)
2273
7eb456c4ed8a Replace all occurrences of AVERROR_NOMEM with AVERROR(ENOMEM).
takis
parents: 2001
diff changeset
245 return AVERROR(ENOMEM);
818
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
246
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 818
diff changeset
247 st->codec->codec_type = CODEC_TYPE_AUDIO;
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 818
diff changeset
248 st->codec->codec_id = CODEC_ID_ADPCM_YAMAHA;
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 818
diff changeset
249 st->codec->sample_rate = rate;
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 818
diff changeset
250 st->codec->channels = 1;
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 818
diff changeset
251 st->codec->bits_per_sample = 4;
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 818
diff changeset
252 st->codec->bit_rate = st->codec->sample_rate * st->codec->bits_per_sample;
818
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
253
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 818
diff changeset
254 av_set_pts_info(st, 64, 1, st->codec->sample_rate);
818
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
255
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
256 return 0;
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
257 }
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
258
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
259 #define MAX_SIZE 4096
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
260
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
261 static int mmf_read_packet(AVFormatContext *s,
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
262 AVPacket *pkt)
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
263 {
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
264 MMFContext *mmf = s->priv_data;
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
265 AVStream *st;
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
266 int ret, size;
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
267
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
268 if (url_feof(&s->pb))
2274
b21c2af60bc9 Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents: 2273
diff changeset
269 return AVERROR(EIO);
818
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
270 st = s->streams[0];
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
271
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
272 size = MAX_SIZE;
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
273 if(size > mmf->data_size)
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
274 size = mmf->data_size;
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
275
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
276 if(!size)
2274
b21c2af60bc9 Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents: 2273
diff changeset
277 return AVERROR(EIO);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
278
818
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
279 if (av_new_packet(pkt, size))
2274
b21c2af60bc9 Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents: 2273
diff changeset
280 return AVERROR(EIO);
818
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
281 pkt->stream_index = 0;
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
282
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
283 ret = get_buffer(&s->pb, pkt->data, pkt->size);
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
284 if (ret < 0)
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
285 av_free_packet(pkt);
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
286
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
287 mmf->data_size -= ret;
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
288
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
289 pkt->size = ret;
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
290 return ret;
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
291 }
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
292
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
293 static int mmf_read_close(AVFormatContext *s)
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
294 {
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
295 return 0;
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
296 }
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
297
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
298 static int mmf_read_seek(AVFormatContext *s,
818
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
299 int stream_index, int64_t timestamp, int flags)
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
300 {
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
301 return pcm_read_seek(s, stream_index, timestamp, flags);
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
302 }
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
303
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
304 #ifdef CONFIG_MMF_DEMUXER
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
305 AVInputFormat mmf_demuxer = {
818
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
306 "mmf",
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
307 "mmf format",
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
308 sizeof(MMFContext),
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
309 mmf_probe,
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
310 mmf_read_header,
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
311 mmf_read_packet,
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
312 mmf_read_close,
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
313 mmf_read_seek,
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
314 };
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
315 #endif
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
316 #ifdef CONFIG_MMF_MUXER
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
317 AVOutputFormat mmf_muxer = {
818
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
318 "mmf",
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
319 "mmf format",
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
320 "application/vnd.smaf",
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
321 "mmf",
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
322 sizeof(MMFContext),
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
323 CODEC_ID_ADPCM_YAMAHA,
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
324 CODEC_ID_NONE,
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
325 mmf_write_header,
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
326 mmf_write_packet,
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
327 mmf_write_trailer,
b1d7ee1c792d Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff changeset
328 };
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
329 #endif