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