Mercurial > libavformat.hg
annotate mmf.c @ 912:844bc9093aa3 libavformat
Remove all stray tabs and trailing whitespace, this time for good.
author | diego |
---|---|
date | Tue, 24 Jan 2006 10:33:14 +0000 |
parents | 5d1bcf01ce28 |
children | fab79efcd476 |
rev | line source |
---|---|
885 | 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 * |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
5 * This library is free software; you can redistribute it and/or |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
6 * 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
|
7 * License as published by the Free Software Foundation; either |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
8 * version 2 of the License, or (at your option) any later version. |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
9 * |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
10 * This library is distributed in the hope that it will be useful, |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
11 * 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
|
12 * 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
|
13 * Lesser General Public License for more details. |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
14 * |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
15 * You should have received a copy of the GNU Lesser General Public |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
16 * License along with this library; if not, write to the Free Software |
896
edbe5c3717f9
Update licensing information: The FSF changed postal address.
diego
parents:
885
diff
changeset
|
17 * 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
|
18 */ |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
19 #include "avformat.h" |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
20 #include "avi.h" |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
21 |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
22 typedef struct { |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
23 offset_t atrpos, atsqpos, awapos; |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
24 offset_t data_size; |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
25 } MMFContext; |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
26 |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
27 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
|
28 |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
29 static int mmf_rate_code(int rate) |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
30 { |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
31 int i; |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
32 for(i = 0; i < 5; i++) |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
33 if(mmf_rates[i] == rate) |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
34 return i; |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
35 return -1; |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
36 } |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
37 |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
38 static int mmf_rate(int code) |
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 if((code < 0) || (code > 4)) |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
41 return -1; |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
42 return mmf_rates[code]; |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
43 } |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
44 |
902 | 45 #ifdef CONFIG_MUXERS |
818
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
46 /* 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
|
47 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
|
48 { |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
49 offset_t pos; |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
50 |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
51 pos = url_ftell(pb); |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
52 url_fseek(pb, start - 4, SEEK_SET); |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
53 put_be32(pb, (uint32_t)(pos - start)); |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
54 url_fseek(pb, pos, SEEK_SET); |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
55 } |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
56 |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
57 static int mmf_write_header(AVFormatContext *s) |
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 MMFContext *mmf = s->priv_data; |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
60 ByteIOContext *pb = &s->pb; |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
61 offset_t pos; |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
62 int rate; |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
63 |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
818
diff
changeset
|
64 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
|
65 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
|
66 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
|
67 return -1; |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
68 } |
885 | 69 |
818
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
70 put_tag(pb, "MMMD"); |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
71 put_be32(pb, 0); |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
72 pos = start_tag(pb, "CNTI"); |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
73 put_byte(pb, 0); /* class */ |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
74 put_byte(pb, 0); /* type */ |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
75 put_byte(pb, 0); /* code type */ |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
76 put_byte(pb, 0); /* status */ |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
77 put_byte(pb, 0); /* counts */ |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
78 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
|
79 end_tag_be(pb, pos); |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
80 |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
81 put_buffer(pb, "ATR\x00", 4); |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
82 put_be32(pb, 0); |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
83 mmf->atrpos = url_ftell(pb); |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
84 put_byte(pb, 0); /* format type */ |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
85 put_byte(pb, 0); /* sequence type */ |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
86 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
|
87 put_byte(pb, 0); /* wave base bit */ |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
88 put_byte(pb, 2); /* time base d */ |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
89 put_byte(pb, 2); /* time base g */ |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
90 |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
91 put_tag(pb, "Atsq"); |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
92 put_be32(pb, 16); |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
93 mmf->atsqpos = url_ftell(pb); |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
94 /* Will be filled on close */ |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
95 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
|
96 |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
97 mmf->awapos = start_tag(pb, "Awa\x01"); |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
98 |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
818
diff
changeset
|
99 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
|
100 |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
101 put_flush_packet(pb); |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
102 |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
103 return 0; |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
104 } |
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 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
|
107 { |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
108 ByteIOContext *pb = &s->pb; |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
109 put_buffer(pb, pkt->data, pkt->size); |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
110 return 0; |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
111 } |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
112 |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
113 /* Write a variable-length symbol */ |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
114 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
|
115 { |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
116 if(val < 128) |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
117 put_byte(pb, val); |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
118 else { |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
119 val -= 128; |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
120 put_byte(pb, 0x80 | val >> 7); |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
121 put_byte(pb, 0x7f & val); |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
122 } |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
123 } |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
124 |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
125 static int mmf_write_trailer(AVFormatContext *s) |
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 ByteIOContext *pb = &s->pb; |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
128 MMFContext *mmf = s->priv_data; |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
129 offset_t pos, size; |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
130 int gatetime; |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
131 |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
132 if (!url_is_streamed(&s->pb)) { |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
133 /* Fill in length fields */ |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
134 end_tag_be(pb, mmf->awapos); |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
135 end_tag_be(pb, mmf->atrpos); |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
136 end_tag_be(pb, 8); |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
137 |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
138 pos = url_ftell(pb); |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
139 size = pos - mmf->awapos; |
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 /* Fill Atsq chunk */ |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
142 url_fseek(pb, mmf->atsqpos, SEEK_SET); |
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 /* "play wav" */ |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
145 put_byte(pb, 0); /* start time */ |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
146 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
|
147 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
|
148 put_varlength(pb, gatetime); /* duration */ |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
149 |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
150 /* "nop" */ |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
151 put_varlength(pb, gatetime); /* start time */ |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
152 put_buffer(pb, "\xff\x00", 2); /* nop */ |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
153 |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
154 /* "end of sequence" */ |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
155 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
|
156 |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
157 url_fseek(pb, pos, SEEK_SET); |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
158 |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
159 put_flush_packet(pb); |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
160 } |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
161 return 0; |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
162 } |
858
66cc656ea404
Replace CONFIG_ENCODERS/CONFIG_DECODERS with CONFIG_MUXERS/CONFIG_DEMUXERS
diego
parents:
856
diff
changeset
|
163 #endif //CONFIG_MUXERS |
818
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
164 |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
165 static int mmf_probe(AVProbeData *p) |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
166 { |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
167 /* check file header */ |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
168 if (p->buf_size <= 32) |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
169 return 0; |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
170 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
|
171 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
|
172 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
|
173 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
|
174 return AVPROBE_SCORE_MAX; |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
175 else |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
176 return 0; |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
177 } |
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 /* mmf input */ |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
180 static int mmf_read_header(AVFormatContext *s, |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
181 AVFormatParameters *ap) |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
182 { |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
183 MMFContext *mmf = s->priv_data; |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
184 unsigned int tag; |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
185 ByteIOContext *pb = &s->pb; |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
186 AVStream *st; |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
187 offset_t file_size, size; |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
188 int rate, params; |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
189 |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
190 tag = get_le32(pb); |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
191 if (tag != MKTAG('M', 'M', 'M', 'D')) |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
192 return -1; |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
193 file_size = get_be32(pb); |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
194 |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
195 /* 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
|
196 for(;; url_fseek(pb, size, SEEK_CUR)) { |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
197 tag = get_le32(pb); |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
198 size = get_be32(pb); |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
199 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
|
200 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
|
201 break; |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
202 } |
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 /* Tag = "ATRx", where "x" = track number */ |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
205 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
|
206 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
|
207 return -1; |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
208 } |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
209 |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
210 get_byte(pb); /* format type */ |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
211 get_byte(pb); /* sequence type */ |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
212 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
|
213 rate = mmf_rate(params & 0x0f); |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
214 if(rate < 0) { |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
215 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
|
216 return -1; |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
217 } |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
218 get_byte(pb); /* wave base bit */ |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
219 get_byte(pb); /* time base d */ |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
220 get_byte(pb); /* time base g */ |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
221 |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
222 /* 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
|
223 for(;; url_fseek(pb, size, SEEK_CUR)) { |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
224 tag = get_le32(pb); |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
225 size = get_be32(pb); |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
226 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
|
227 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
|
228 break; |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
229 } |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
230 |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
231 /* 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
|
232 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
|
233 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
|
234 return -1; |
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 mmf->data_size = size; |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
237 |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
238 st = av_new_stream(s, 0); |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
239 if (!st) |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
240 return AVERROR_NOMEM; |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
241 |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
818
diff
changeset
|
242 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
|
243 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
|
244 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
|
245 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
|
246 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
|
247 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
|
248 |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
818
diff
changeset
|
249 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
|
250 |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
251 return 0; |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
252 } |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
253 |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
254 #define MAX_SIZE 4096 |
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 static int mmf_read_packet(AVFormatContext *s, |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
257 AVPacket *pkt) |
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 MMFContext *mmf = s->priv_data; |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
260 AVStream *st; |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
261 int ret, size; |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
262 |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
263 if (url_feof(&s->pb)) |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
264 return AVERROR_IO; |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
265 st = s->streams[0]; |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
266 |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
267 size = MAX_SIZE; |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
268 if(size > mmf->data_size) |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
269 size = mmf->data_size; |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
270 |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
271 if(!size) |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
272 return AVERROR_IO; |
885 | 273 |
818
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
274 if (av_new_packet(pkt, size)) |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
275 return AVERROR_IO; |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
276 pkt->stream_index = 0; |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
277 |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
278 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
|
279 if (ret < 0) |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
280 av_free_packet(pkt); |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
281 |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
282 mmf->data_size -= ret; |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
283 |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
284 pkt->size = ret; |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
285 return ret; |
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 |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
288 static int mmf_read_close(AVFormatContext *s) |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
289 { |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
290 return 0; |
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 |
885 | 293 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
|
294 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
|
295 { |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
296 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
|
297 } |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
298 |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
299 |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
300 static AVInputFormat mmf_iformat = { |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
301 "mmf", |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
302 "mmf format", |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
303 sizeof(MMFContext), |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
304 mmf_probe, |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
305 mmf_read_header, |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
306 mmf_read_packet, |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
307 mmf_read_close, |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
308 mmf_read_seek, |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
309 }; |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
310 |
858
66cc656ea404
Replace CONFIG_ENCODERS/CONFIG_DECODERS with CONFIG_MUXERS/CONFIG_DEMUXERS
diego
parents:
856
diff
changeset
|
311 #ifdef CONFIG_MUXERS |
818
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
312 static AVOutputFormat mmf_oformat = { |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
313 "mmf", |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
314 "mmf format", |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
315 "application/vnd.smaf", |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
316 "mmf", |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
317 sizeof(MMFContext), |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
318 CODEC_ID_ADPCM_YAMAHA, |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
319 CODEC_ID_NONE, |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
320 mmf_write_header, |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
321 mmf_write_packet, |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
322 mmf_write_trailer, |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
323 }; |
858
66cc656ea404
Replace CONFIG_ENCODERS/CONFIG_DECODERS with CONFIG_MUXERS/CONFIG_DEMUXERS
diego
parents:
856
diff
changeset
|
324 #endif //CONFIG_MUXERS |
818
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
325 |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
326 int ff_mmf_init(void) |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
327 { |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
328 av_register_input_format(&mmf_iformat); |
858
66cc656ea404
Replace CONFIG_ENCODERS/CONFIG_DECODERS with CONFIG_MUXERS/CONFIG_DEMUXERS
diego
parents:
856
diff
changeset
|
329 #ifdef CONFIG_MUXERS |
818
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
330 av_register_output_format(&mmf_oformat); |
858
66cc656ea404
Replace CONFIG_ENCODERS/CONFIG_DECODERS with CONFIG_MUXERS/CONFIG_DEMUXERS
diego
parents:
856
diff
changeset
|
331 #endif //CONFIG_MUXERS |
818
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
332 return 0; |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
333 } |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
334 |