Mercurial > libavformat.hg
annotate mmf.c @ 1335:2cbaaf63ce18 libavformat
add lpcm fourcc
author | bcoudurier |
---|---|
date | Thu, 28 Sep 2006 17:54:59 +0000 |
parents | 6a5e58d2114b |
children | 0899bfe4105c |
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" |
1142
e3a585883bbd
Move initialisations and internal symbols in allformats.h,
gpoirier
parents:
1065
diff
changeset
|
20 #include "allformats.h" |
1172
6a5e58d2114b
move common stuff from avienc.c and wav.c to new file riff.c
mru
parents:
1169
diff
changeset
|
21 #include "riff.h" |
818
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
22 |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
23 typedef struct { |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
24 offset_t atrpos, atsqpos, awapos; |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
25 offset_t data_size; |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
26 } MMFContext; |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
27 |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
28 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
|
29 |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
30 static int mmf_rate_code(int rate) |
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 int i; |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
33 for(i = 0; i < 5; i++) |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
34 if(mmf_rates[i] == rate) |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
35 return i; |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
36 return -1; |
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 |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
39 static int mmf_rate(int code) |
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 if((code < 0) || (code > 4)) |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
42 return -1; |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
43 return mmf_rates[code]; |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
44 } |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
45 |
902 | 46 #ifdef CONFIG_MUXERS |
818
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
47 /* 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
|
48 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
|
49 { |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
50 offset_t pos; |
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 pos = url_ftell(pb); |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
53 url_fseek(pb, start - 4, SEEK_SET); |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
54 put_be32(pb, (uint32_t)(pos - start)); |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
55 url_fseek(pb, pos, SEEK_SET); |
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 |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
58 static int mmf_write_header(AVFormatContext *s) |
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 MMFContext *mmf = s->priv_data; |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
61 ByteIOContext *pb = &s->pb; |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
62 offset_t pos; |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
63 int rate; |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
64 |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
818
diff
changeset
|
65 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
|
66 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
|
67 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
|
68 return -1; |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
69 } |
885 | 70 |
818
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
71 put_tag(pb, "MMMD"); |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
72 put_be32(pb, 0); |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
73 pos = start_tag(pb, "CNTI"); |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
74 put_byte(pb, 0); /* class */ |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
75 put_byte(pb, 0); /* type */ |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
76 put_byte(pb, 0); /* code type */ |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
77 put_byte(pb, 0); /* status */ |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
78 put_byte(pb, 0); /* counts */ |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
79 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
|
80 end_tag_be(pb, pos); |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
81 |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
82 put_buffer(pb, "ATR\x00", 4); |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
83 put_be32(pb, 0); |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
84 mmf->atrpos = url_ftell(pb); |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
85 put_byte(pb, 0); /* format type */ |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
86 put_byte(pb, 0); /* sequence type */ |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
87 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
|
88 put_byte(pb, 0); /* wave base bit */ |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
89 put_byte(pb, 2); /* time base d */ |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
90 put_byte(pb, 2); /* time base g */ |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
91 |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
92 put_tag(pb, "Atsq"); |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
93 put_be32(pb, 16); |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
94 mmf->atsqpos = url_ftell(pb); |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
95 /* Will be filled on close */ |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
96 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
|
97 |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
98 mmf->awapos = start_tag(pb, "Awa\x01"); |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
99 |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
818
diff
changeset
|
100 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
|
101 |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
102 put_flush_packet(pb); |
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 return 0; |
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 |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
107 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
|
108 { |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
109 ByteIOContext *pb = &s->pb; |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
110 put_buffer(pb, pkt->data, pkt->size); |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
111 return 0; |
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 |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
114 /* Write a variable-length symbol */ |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
115 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
|
116 { |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
117 if(val < 128) |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
118 put_byte(pb, val); |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
119 else { |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
120 val -= 128; |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
121 put_byte(pb, 0x80 | val >> 7); |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
122 put_byte(pb, 0x7f & val); |
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 |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
126 static int mmf_write_trailer(AVFormatContext *s) |
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 ByteIOContext *pb = &s->pb; |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
129 MMFContext *mmf = s->priv_data; |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
130 offset_t pos, size; |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
131 int gatetime; |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
132 |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
133 if (!url_is_streamed(&s->pb)) { |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
134 /* Fill in length fields */ |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
135 end_tag_be(pb, mmf->awapos); |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
136 end_tag_be(pb, mmf->atrpos); |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
137 end_tag_be(pb, 8); |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
138 |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
139 pos = url_ftell(pb); |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
140 size = pos - mmf->awapos; |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
141 |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
142 /* Fill Atsq chunk */ |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
143 url_fseek(pb, mmf->atsqpos, SEEK_SET); |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
144 |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
145 /* "play wav" */ |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
146 put_byte(pb, 0); /* start time */ |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
147 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
|
148 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
|
149 put_varlength(pb, gatetime); /* duration */ |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
150 |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
151 /* "nop" */ |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
152 put_varlength(pb, gatetime); /* start time */ |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
153 put_buffer(pb, "\xff\x00", 2); /* nop */ |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
154 |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
155 /* "end of sequence" */ |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
156 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
|
157 |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
158 url_fseek(pb, pos, SEEK_SET); |
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 put_flush_packet(pb); |
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 return 0; |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
163 } |
858
66cc656ea404
Replace CONFIG_ENCODERS/CONFIG_DECODERS with CONFIG_MUXERS/CONFIG_DEMUXERS
diego
parents:
856
diff
changeset
|
164 #endif //CONFIG_MUXERS |
818
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
165 |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
166 static int mmf_probe(AVProbeData *p) |
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 /* check file header */ |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
169 if (p->buf_size <= 32) |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
170 return 0; |
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) |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
245 return AVERROR_NOMEM; |
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)) |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
269 return AVERROR_IO; |
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) |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
277 return AVERROR_IO; |
885 | 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)) |
b1d7ee1c792d
Yamaha SMAF file format support patch by (Vidar Madsen: vidarino, gmail com)
michael
parents:
diff
changeset
|
280 return AVERROR_IO; |
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 | 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 | 304 #ifdef CONFIG_MMF_DEMUXER |
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 | 315 #endif |
316 #ifdef CONFIG_MMF_MUXER | |
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 | 329 #endif |