Mercurial > libavformat.hg
annotate dv.c @ 3805:d8a6432c76f3 libavformat
use strlen and do not write useless trailing 0 according to specs
author | bcoudurier |
---|---|
date | Sat, 30 Aug 2008 22:24:19 +0000 |
parents | a8a70ae19206 |
children | bf1b4748cd2e |
rev | line source |
---|---|
885 | 1 /* |
2 * General DV muxer/demuxer | |
933 | 3 * Copyright (c) 2003 Roman Shaposhnik |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
4 * |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
5 * Many thanks to Dan Dennedy <dan@dennedy.org> for providing wealth |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
6 * of DV technical info. |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
7 * |
0 | 8 * Raw DV format |
9 * Copyright (c) 2002 Fabrice Bellard. | |
10 * | |
3790
a8a70ae19206
Intial implementation of the DV100 (AKA DVCPRO HD) decoder and demuxer as
romansh
parents:
3787
diff
changeset
|
11 * 50 Mbps (DVCPRO50) and 100 Mbps (DVCPRO HD) support |
995 | 12 * Copyright (c) 2006 Daniel Maas <dmaas@maasdigital.com> |
3790
a8a70ae19206
Intial implementation of the DV100 (AKA DVCPRO HD) decoder and demuxer as
romansh
parents:
3787
diff
changeset
|
13 * Funded by BBC Research & Development |
995 | 14 * |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1317
diff
changeset
|
15 * This file is part of FFmpeg. |
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1317
diff
changeset
|
16 * |
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1317
diff
changeset
|
17 * FFmpeg is free software; you can redistribute it and/or |
0 | 18 * modify it under the terms of the GNU Lesser General Public |
19 * 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:
1317
diff
changeset
|
20 * version 2.1 of the License, or (at your option) any later version. |
0 | 21 * |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1317
diff
changeset
|
22 * FFmpeg is distributed in the hope that it will be useful, |
0 | 23 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
25 * Lesser General Public License for more details. | |
26 * | |
27 * 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:
1317
diff
changeset
|
28 * License along with FFmpeg; if not, write to the Free Software |
896
edbe5c3717f9
Update licensing information: The FSF changed postal address.
diego
parents:
887
diff
changeset
|
29 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
0 | 30 */ |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
31 #include <time.h> |
0 | 32 #include "avformat.h" |
3286 | 33 #include "libavcodec/dvdata.h" |
296
252946de6d3f
* DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents:
288
diff
changeset
|
34 #include "dv.h" |
0 | 35 |
296
252946de6d3f
* DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents:
288
diff
changeset
|
36 struct DVDemuxContext { |
995 | 37 const DVprofile* sys; /* Current DV profile. E.g.: 525/60, 625/50 */ |
296
252946de6d3f
* DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents:
288
diff
changeset
|
38 AVFormatContext* fctx; |
252946de6d3f
* DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents:
288
diff
changeset
|
39 AVStream* vst; |
3790
a8a70ae19206
Intial implementation of the DV100 (AKA DVCPRO HD) decoder and demuxer as
romansh
parents:
3787
diff
changeset
|
40 AVStream* ast[4]; |
a8a70ae19206
Intial implementation of the DV100 (AKA DVCPRO HD) decoder and demuxer as
romansh
parents:
3787
diff
changeset
|
41 AVPacket audio_pkt[4]; |
a8a70ae19206
Intial implementation of the DV100 (AKA DVCPRO HD) decoder and demuxer as
romansh
parents:
3787
diff
changeset
|
42 uint8_t audio_buf[4][8192]; |
296
252946de6d3f
* DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents:
288
diff
changeset
|
43 int ach; |
392 | 44 int frames; |
45 uint64_t abytes; | |
296
252946de6d3f
* DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents:
288
diff
changeset
|
46 }; |
0 | 47 |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
48 static inline uint16_t dv_audio_12to16(uint16_t sample) |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
49 { |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
50 uint16_t shift, result; |
885 | 51 |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
52 sample = (sample < 0x800) ? sample : sample | 0xf000; |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
53 shift = (sample & 0xf00) >> 8; |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
54 |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
55 if (shift < 0x2 || shift > 0xd) { |
887 | 56 result = sample; |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
57 } else if (shift < 0x8) { |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
58 shift--; |
887 | 59 result = (sample - (256 * shift)) << shift; |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
60 } else { |
887 | 61 shift = 0xe - shift; |
62 result = ((sample + ((256 * shift) + 1)) << shift) - 1; | |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
63 } |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
64 |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
65 return result; |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
66 } |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
67 |
885 | 68 /* |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
69 * This is the dumbest implementation of all -- it simply looks at |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
70 * a fixed offset and if pack isn't there -- fails. We might want |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
71 * to have a fallback mechanism for complete search of missing packs. |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
72 */ |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
73 static const uint8_t* dv_extract_pack(uint8_t* frame, enum dv_pack_type t) |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
74 { |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
75 int offs; |
885 | 76 |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
77 switch (t) { |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
78 case dv_audio_source: |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
79 offs = (80*6 + 80*16*3 + 3); |
887 | 80 break; |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
81 case dv_audio_control: |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
82 offs = (80*6 + 80*16*4 + 3); |
887 | 83 break; |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
84 case dv_video_control: |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
85 offs = (80*5 + 48 + 5); |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
86 break; |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
87 default: |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
88 return NULL; |
885 | 89 } |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
90 |
3278 | 91 return frame[offs] == t ? &frame[offs] : NULL; |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
92 } |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
93 |
885 | 94 /* |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
95 * There's a couple of assumptions being made here: |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
96 * 1. By default we silence erroneous (0x8000/16bit 0x800/12bit) audio samples. |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
97 * We can pass them upwards when ffmpeg will be ready to deal with them. |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
98 * 2. We don't do software emphasis. |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
99 * 3. Audio is always returned as 16bit linear samples: 12bit nonlinear samples |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
100 * are converted into 16bit linear ones. |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
101 */ |
3790
a8a70ae19206
Intial implementation of the DV100 (AKA DVCPRO HD) decoder and demuxer as
romansh
parents:
3787
diff
changeset
|
102 static int dv_extract_audio(uint8_t* frame, uint8_t* ppcm[4], |
995 | 103 const DVprofile *sys) |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
104 { |
995 | 105 int size, chan, i, j, d, of, smpls, freq, quant, half_ch; |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
106 uint16_t lc, rc; |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
107 const uint8_t* as_pack; |
3790
a8a70ae19206
Intial implementation of the DV100 (AKA DVCPRO HD) decoder and demuxer as
romansh
parents:
3787
diff
changeset
|
108 uint8_t *pcm, ipcm; |
885 | 109 |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
110 as_pack = dv_extract_pack(frame, dv_audio_source); |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
111 if (!as_pack) /* No audio ? */ |
887 | 112 return 0; |
885 | 113 |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
114 smpls = as_pack[1] & 0x3f; /* samples in this frame - min. samples */ |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
115 freq = (as_pack[4] >> 3) & 0x07; /* 0 - 48KHz, 1 - 44,1kHz, 2 - 32 kHz */ |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
116 quant = as_pack[4] & 0x07; /* 0 - 16bit linear, 1 - 12bit nonlinear */ |
885 | 117 |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
118 if (quant > 1) |
887 | 119 return -1; /* Unsupported quantization */ |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
120 |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
121 size = (sys->audio_min_samples[freq] + smpls) * 4; /* 2ch, 2bytes */ |
296
252946de6d3f
* DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents:
288
diff
changeset
|
122 half_ch = sys->difseg_size/2; |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
123 |
3790
a8a70ae19206
Intial implementation of the DV100 (AKA DVCPRO HD) decoder and demuxer as
romansh
parents:
3787
diff
changeset
|
124 /* We work with 720p frames split in half, thus even frames have channels 0,1 and odd 2,3 */ |
a8a70ae19206
Intial implementation of the DV100 (AKA DVCPRO HD) decoder and demuxer as
romansh
parents:
3787
diff
changeset
|
125 ipcm = (sys->height == 720 && ((frame[1]>>2)&0x3) == 0)?2:0; |
a8a70ae19206
Intial implementation of the DV100 (AKA DVCPRO HD) decoder and demuxer as
romansh
parents:
3787
diff
changeset
|
126 pcm = ppcm[ipcm++]; |
a8a70ae19206
Intial implementation of the DV100 (AKA DVCPRO HD) decoder and demuxer as
romansh
parents:
3787
diff
changeset
|
127 |
995 | 128 /* for each DIF channel */ |
129 for (chan = 0; chan < sys->n_difchan; chan++) { | |
130 /* for each DIF segment */ | |
131 for (i = 0; i < sys->difseg_size; i++) { | |
132 frame += 6 * 80; /* skip DIF segment header */ | |
133 if (quant == 1 && i == half_ch) { | |
134 /* next stereo channel (12bit mode only) */ | |
3790
a8a70ae19206
Intial implementation of the DV100 (AKA DVCPRO HD) decoder and demuxer as
romansh
parents:
3787
diff
changeset
|
135 pcm = ppcm[ipcm++]; |
a8a70ae19206
Intial implementation of the DV100 (AKA DVCPRO HD) decoder and demuxer as
romansh
parents:
3787
diff
changeset
|
136 if (!pcm) |
995 | 137 break; |
138 } | |
296
252946de6d3f
* DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents:
288
diff
changeset
|
139 |
995 | 140 /* for each AV sequence */ |
141 for (j = 0; j < 9; j++) { | |
142 for (d = 8; d < 80; d += 2) { | |
143 if (quant == 0) { /* 16bit quantization */ | |
144 of = sys->audio_shuffle[i][j] + (d - 8)/2 * sys->audio_stride; | |
145 if (of*2 >= size) | |
146 continue; | |
885 | 147 |
995 | 148 pcm[of*2] = frame[d+1]; // FIXME: may be we have to admit |
149 pcm[of*2+1] = frame[d]; // that DV is a big endian PCM | |
150 if (pcm[of*2+1] == 0x80 && pcm[of*2] == 0x00) | |
151 pcm[of*2+1] = 0; | |
152 } else { /* 12bit quantization */ | |
153 lc = ((uint16_t)frame[d] << 4) | | |
154 ((uint16_t)frame[d+2] >> 4); | |
155 rc = ((uint16_t)frame[d+1] << 4) | | |
156 ((uint16_t)frame[d+2] & 0x0f); | |
157 lc = (lc == 0x800 ? 0 : dv_audio_12to16(lc)); | |
158 rc = (rc == 0x800 ? 0 : dv_audio_12to16(rc)); | |
159 | |
160 of = sys->audio_shuffle[i%half_ch][j] + (d - 8)/3 * sys->audio_stride; | |
161 if (of*2 >= size) | |
162 continue; | |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
163 |
995 | 164 pcm[of*2] = lc & 0xff; // FIXME: may be we have to admit |
165 pcm[of*2+1] = lc >> 8; // that DV is a big endian PCM | |
166 of = sys->audio_shuffle[i%half_ch+half_ch][j] + | |
167 (d - 8)/3 * sys->audio_stride; | |
168 pcm[of*2] = rc & 0xff; // FIXME: may be we have to admit | |
169 pcm[of*2+1] = rc >> 8; // that DV is a big endian PCM | |
170 ++d; | |
171 } | |
172 } | |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
173 |
995 | 174 frame += 16 * 80; /* 15 Video DIFs + 1 Audio DIF */ |
175 } | |
176 } | |
885 | 177 |
3790
a8a70ae19206
Intial implementation of the DV100 (AKA DVCPRO HD) decoder and demuxer as
romansh
parents:
3787
diff
changeset
|
178 /* next stereo channel (50Mbps and 100Mbps only) */ |
a8a70ae19206
Intial implementation of the DV100 (AKA DVCPRO HD) decoder and demuxer as
romansh
parents:
3787
diff
changeset
|
179 pcm = ppcm[ipcm++]; |
a8a70ae19206
Intial implementation of the DV100 (AKA DVCPRO HD) decoder and demuxer as
romansh
parents:
3787
diff
changeset
|
180 if (!pcm) |
995 | 181 break; |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
182 } |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
183 |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
184 return size; |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
185 } |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
186 |
296
252946de6d3f
* DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents:
288
diff
changeset
|
187 static int dv_extract_audio_info(DVDemuxContext* c, uint8_t* frame) |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
188 { |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
189 const uint8_t* as_pack; |
995 | 190 int freq, stype, smpls, quant, i, ach; |
37 | 191 |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
192 as_pack = dv_extract_pack(frame, dv_audio_source); |
995 | 193 if (!as_pack || !c->sys) { /* No audio ? */ |
296
252946de6d3f
* DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents:
288
diff
changeset
|
194 c->ach = 0; |
887 | 195 return 0; |
296
252946de6d3f
* DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents:
288
diff
changeset
|
196 } |
885 | 197 |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
198 smpls = as_pack[1] & 0x3f; /* samples in this frame - min. samples */ |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
199 freq = (as_pack[4] >> 3) & 0x07; /* 0 - 48KHz, 1 - 44,1kHz, 2 - 32 kHz */ |
3787
6f3cdf5fb948
Two cosmetic changes for improved readability and ease of HDVCPRO HD integration
romansh
parents:
3759
diff
changeset
|
200 stype = (as_pack[3] & 0x1f); /* 0 - 2CH, 2 - 4CH, 3 - 8CH */ |
296
252946de6d3f
* DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents:
288
diff
changeset
|
201 quant = as_pack[4] & 0x07; /* 0 - 16bit linear, 1 - 12bit nonlinear */ |
995 | 202 |
203 /* note: ach counts PAIRS of channels (i.e. stereo channels) */ | |
3790
a8a70ae19206
Intial implementation of the DV100 (AKA DVCPRO HD) decoder and demuxer as
romansh
parents:
3787
diff
changeset
|
204 if (stype == 3) { |
a8a70ae19206
Intial implementation of the DV100 (AKA DVCPRO HD) decoder and demuxer as
romansh
parents:
3787
diff
changeset
|
205 ach = 4; |
a8a70ae19206
Intial implementation of the DV100 (AKA DVCPRO HD) decoder and demuxer as
romansh
parents:
3787
diff
changeset
|
206 } else |
995 | 207 ach = (stype == 2 || (quant && (freq == 2))) ? 2 : 1; |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
208 |
532
772247018ade
* experimental dynamic audio stream allocation for DV demuxer. This
romansh
parents:
531
diff
changeset
|
209 /* Dynamic handling of the audio streams in DV */ |
772247018ade
* experimental dynamic audio stream allocation for DV demuxer. This
romansh
parents:
531
diff
changeset
|
210 for (i=0; i<ach; i++) { |
772247018ade
* experimental dynamic audio stream allocation for DV demuxer. This
romansh
parents:
531
diff
changeset
|
211 if (!c->ast[i]) { |
772247018ade
* experimental dynamic audio stream allocation for DV demuxer. This
romansh
parents:
531
diff
changeset
|
212 c->ast[i] = av_new_stream(c->fctx, 0); |
887 | 213 if (!c->ast[i]) |
214 break; | |
215 av_set_pts_info(c->ast[i], 64, 1, 30000); | |
216 c->ast[i]->codec->codec_type = CODEC_TYPE_AUDIO; | |
217 c->ast[i]->codec->codec_id = CODEC_ID_PCM_S16LE; | |
562
bf3231dd1d7c
* static allocation for audio packets. This will make it a little bit
romansh
parents:
560
diff
changeset
|
218 |
bf3231dd1d7c
* static allocation for audio packets. This will make it a little bit
romansh
parents:
560
diff
changeset
|
219 av_init_packet(&c->audio_pkt[i]); |
bf3231dd1d7c
* static allocation for audio packets. This will make it a little bit
romansh
parents:
560
diff
changeset
|
220 c->audio_pkt[i].size = 0; |
bf3231dd1d7c
* static allocation for audio packets. This will make it a little bit
romansh
parents:
560
diff
changeset
|
221 c->audio_pkt[i].data = c->audio_buf[i]; |
bf3231dd1d7c
* static allocation for audio packets. This will make it a little bit
romansh
parents:
560
diff
changeset
|
222 c->audio_pkt[i].stream_index = c->ast[i]->index; |
bf3231dd1d7c
* static allocation for audio packets. This will make it a little bit
romansh
parents:
560
diff
changeset
|
223 c->audio_pkt[i].flags |= PKT_FLAG_KEY; |
532
772247018ade
* experimental dynamic audio stream allocation for DV demuxer. This
romansh
parents:
531
diff
changeset
|
224 } |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
764
diff
changeset
|
225 c->ast[i]->codec->sample_rate = dv_audio_frequency[freq]; |
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
764
diff
changeset
|
226 c->ast[i]->codec->channels = 2; |
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
764
diff
changeset
|
227 c->ast[i]->codec->bit_rate = 2 * dv_audio_frequency[freq] * 16; |
532
772247018ade
* experimental dynamic audio stream allocation for DV demuxer. This
romansh
parents:
531
diff
changeset
|
228 c->ast[i]->start_time = 0; |
296
252946de6d3f
* DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents:
288
diff
changeset
|
229 } |
532
772247018ade
* experimental dynamic audio stream allocation for DV demuxer. This
romansh
parents:
531
diff
changeset
|
230 c->ach = i; |
885 | 231 |
995 | 232 return (c->sys->audio_min_samples[freq] + smpls) * 4; /* 2ch, 2bytes */; |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
233 } |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
234 |
296
252946de6d3f
* DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents:
288
diff
changeset
|
235 static int dv_extract_video_info(DVDemuxContext *c, uint8_t* frame) |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
236 { |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
237 const uint8_t* vsc_pack; |
296
252946de6d3f
* DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents:
288
diff
changeset
|
238 AVCodecContext* avctx; |
252946de6d3f
* DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents:
288
diff
changeset
|
239 int apt, is16_9; |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
240 int size = 0; |
885 | 241 |
995 | 242 if (c->sys) { |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
764
diff
changeset
|
243 avctx = c->vst->codec; |
885 | 244 |
995 | 245 av_set_pts_info(c->vst, 64, c->sys->frame_rate_base, c->sys->frame_rate); |
246 avctx->time_base= (AVRational){c->sys->frame_rate_base, c->sys->frame_rate}; | |
845 | 247 if(!avctx->width){ |
995 | 248 avctx->width = c->sys->width; |
249 avctx->height = c->sys->height; | |
845 | 250 } |
995 | 251 avctx->pix_fmt = c->sys->pix_fmt; |
885 | 252 |
887 | 253 /* finding out SAR is a little bit messy */ |
254 vsc_pack = dv_extract_pack(frame, dv_video_control); | |
296
252946de6d3f
* DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents:
288
diff
changeset
|
255 apt = frame[4] & 0x07; |
887 | 256 is16_9 = (vsc_pack && ((vsc_pack[2] & 0x07) == 0x02 || |
257 (!apt && (vsc_pack[2] & 0x07) == 0x07))); | |
3759
27537074f2a9
convert every muxer/demuxer to write/read sample_aspect_ratio from/to
aurel
parents:
3424
diff
changeset
|
258 c->vst->sample_aspect_ratio = c->sys->sar[is16_9]; |
995 | 259 avctx->bit_rate = av_rescale(c->sys->frame_size * 8, |
260 c->sys->frame_rate, | |
261 c->sys->frame_rate_base); | |
262 size = c->sys->frame_size; | |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
263 } |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
264 return size; |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
265 } |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
266 |
885 | 267 /* |
1317
132206560fe6
Split the DV demuxer and muxer into separate files (as suggested by Diego
takis
parents:
1289
diff
changeset
|
268 * The following 3 functions constitute our interface to the world |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
269 */ |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
270 |
296
252946de6d3f
* DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents:
288
diff
changeset
|
271 DVDemuxContext* dv_init_demux(AVFormatContext *s) |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
272 { |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
273 DVDemuxContext *c; |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
274 |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
275 c = av_mallocz(sizeof(DVDemuxContext)); |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
276 if (!c) |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
277 return NULL; |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
278 |
296
252946de6d3f
* DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents:
288
diff
changeset
|
279 c->vst = av_new_stream(s, 0); |
532
772247018ade
* experimental dynamic audio stream allocation for DV demuxer. This
romansh
parents:
531
diff
changeset
|
280 if (!c->vst) { |
885 | 281 av_free(c); |
532
772247018ade
* experimental dynamic audio stream allocation for DV demuxer. This
romansh
parents:
531
diff
changeset
|
282 return NULL; |
772247018ade
* experimental dynamic audio stream allocation for DV demuxer. This
romansh
parents:
531
diff
changeset
|
283 } |
462
b69898ffc92a
move time_base (pts_num/pts_den) from AVFormatContext -> AVStream
michael
parents:
460
diff
changeset
|
284 |
995 | 285 c->sys = NULL; |
296
252946de6d3f
* DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents:
288
diff
changeset
|
286 c->fctx = s; |
3787
6f3cdf5fb948
Two cosmetic changes for improved readability and ease of HDVCPRO HD integration
romansh
parents:
3759
diff
changeset
|
287 memset(c->ast, 0, sizeof(c->ast)); |
296
252946de6d3f
* DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents:
288
diff
changeset
|
288 c->ach = 0; |
392 | 289 c->frames = 0; |
290 c->abytes = 0; | |
562
bf3231dd1d7c
* static allocation for audio packets. This will make it a little bit
romansh
parents:
560
diff
changeset
|
291 |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
764
diff
changeset
|
292 c->vst->codec->codec_type = CODEC_TYPE_VIDEO; |
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
764
diff
changeset
|
293 c->vst->codec->codec_id = CODEC_ID_DVVIDEO; |
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
764
diff
changeset
|
294 c->vst->codec->bit_rate = 25000000; |
524
0b9dfb0cddc8
* misc. fixes and hacks to improve timing detection in raw DV
romansh
parents:
523
diff
changeset
|
295 c->vst->start_time = 0; |
885 | 296 |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
297 return c; |
0 | 298 } |
299 | |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
300 int dv_get_packet(DVDemuxContext *c, AVPacket *pkt) |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
301 { |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
302 int size = -1; |
296
252946de6d3f
* DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents:
288
diff
changeset
|
303 int i; |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
304 |
296
252946de6d3f
* DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents:
288
diff
changeset
|
305 for (i=0; i<c->ach; i++) { |
252946de6d3f
* DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents:
288
diff
changeset
|
306 if (c->ast[i] && c->audio_pkt[i].size) { |
252946de6d3f
* DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents:
288
diff
changeset
|
307 *pkt = c->audio_pkt[i]; |
887 | 308 c->audio_pkt[i].size = 0; |
309 size = pkt->size; | |
310 break; | |
296
252946de6d3f
* DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents:
288
diff
changeset
|
311 } |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
312 } |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
313 |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
314 return size; |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
315 } |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
316 |
885 | 317 int dv_produce_packet(DVDemuxContext *c, AVPacket *pkt, |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
318 uint8_t* buf, int buf_size) |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
319 { |
296
252946de6d3f
* DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents:
288
diff
changeset
|
320 int size, i; |
3790
a8a70ae19206
Intial implementation of the DV100 (AKA DVCPRO HD) decoder and demuxer as
romansh
parents:
3787
diff
changeset
|
321 uint8_t *ppcm[4] = {0}; |
885 | 322 |
1048 | 323 if (buf_size < DV_PROFILE_BYTES || |
324 !(c->sys = dv_frame_profile(buf)) || | |
325 buf_size < c->sys->frame_size) { | |
326 return -1; /* Broken frame, or not enough data */ | |
327 } | |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
328 |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
329 /* Queueing audio packet */ |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
330 /* FIXME: in case of no audio/bad audio we have to do something */ |
296
252946de6d3f
* DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents:
288
diff
changeset
|
331 size = dv_extract_audio_info(c, buf); |
252946de6d3f
* DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents:
288
diff
changeset
|
332 for (i=0; i<c->ach; i++) { |
562
bf3231dd1d7c
* static allocation for audio packets. This will make it a little bit
romansh
parents:
560
diff
changeset
|
333 c->audio_pkt[i].size = size; |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
764
diff
changeset
|
334 c->audio_pkt[i].pts = c->abytes * 30000*8 / c->ast[i]->codec->bit_rate; |
3790
a8a70ae19206
Intial implementation of the DV100 (AKA DVCPRO HD) decoder and demuxer as
romansh
parents:
3787
diff
changeset
|
335 ppcm[i] = c->audio_buf[i]; |
296
252946de6d3f
* DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents:
288
diff
changeset
|
336 } |
3790
a8a70ae19206
Intial implementation of the DV100 (AKA DVCPRO HD) decoder and demuxer as
romansh
parents:
3787
diff
changeset
|
337 dv_extract_audio(buf, ppcm, c->sys); |
392 | 338 c->abytes += size; |
885 | 339 |
3790
a8a70ae19206
Intial implementation of the DV100 (AKA DVCPRO HD) decoder and demuxer as
romansh
parents:
3787
diff
changeset
|
340 /* We work with 720p frames split in half, thus even frames have channels 0,1 and odd 2,3 */ |
a8a70ae19206
Intial implementation of the DV100 (AKA DVCPRO HD) decoder and demuxer as
romansh
parents:
3787
diff
changeset
|
341 if (c->sys->height == 720) { |
a8a70ae19206
Intial implementation of the DV100 (AKA DVCPRO HD) decoder and demuxer as
romansh
parents:
3787
diff
changeset
|
342 if (((buf[1]>>2)&0x3)) |
a8a70ae19206
Intial implementation of the DV100 (AKA DVCPRO HD) decoder and demuxer as
romansh
parents:
3787
diff
changeset
|
343 c->audio_pkt[2].size = c->audio_pkt[3].size = 0; |
a8a70ae19206
Intial implementation of the DV100 (AKA DVCPRO HD) decoder and demuxer as
romansh
parents:
3787
diff
changeset
|
344 else |
a8a70ae19206
Intial implementation of the DV100 (AKA DVCPRO HD) decoder and demuxer as
romansh
parents:
3787
diff
changeset
|
345 c->audio_pkt[0].size = c->audio_pkt[1].size = 0; |
a8a70ae19206
Intial implementation of the DV100 (AKA DVCPRO HD) decoder and demuxer as
romansh
parents:
3787
diff
changeset
|
346 } |
a8a70ae19206
Intial implementation of the DV100 (AKA DVCPRO HD) decoder and demuxer as
romansh
parents:
3787
diff
changeset
|
347 |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
348 /* Now it's time to return video packet */ |
296
252946de6d3f
* DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents:
288
diff
changeset
|
349 size = dv_extract_video_info(c, buf); |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
350 av_init_packet(pkt); |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
351 pkt->data = buf; |
885 | 352 pkt->size = size; |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
353 pkt->flags |= PKT_FLAG_KEY; |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
354 pkt->stream_index = c->vst->id; |
741 | 355 pkt->pts = c->frames; |
885 | 356 |
392 | 357 c->frames++; |
296
252946de6d3f
* DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents:
288
diff
changeset
|
358 |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
359 return size; |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
360 } |
885 | 361 |
559
f5f85a07fafe
flags, rounding and cliping fix by (Nathan Kurz <nate at verse dot com>)
michael
parents:
532
diff
changeset
|
362 static int64_t dv_frame_offset(AVFormatContext *s, DVDemuxContext *c, |
f5f85a07fafe
flags, rounding and cliping fix by (Nathan Kurz <nate at verse dot com>)
michael
parents:
532
diff
changeset
|
363 int64_t timestamp, int flags) |
392 | 364 { |
523
d788959a01e2
* seek in raw DV patch by Nathan Kurz (nate at verse dot com)
romansh
parents:
515
diff
changeset
|
365 // FIXME: sys may be wrong if last dv_read_packet() failed (buffer is junk) |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
764
diff
changeset
|
366 const DVprofile* sys = dv_codec_profile(c->vst->codec); |
741 | 367 int64_t offset; |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2274
diff
changeset
|
368 int64_t size = url_fsize(s->pb); |
559
f5f85a07fafe
flags, rounding and cliping fix by (Nathan Kurz <nate at verse dot com>)
michael
parents:
532
diff
changeset
|
369 int64_t max_offset = ((size-1) / sys->frame_size) * sys->frame_size; |
392 | 370 |
741 | 371 offset = sys->frame_size * timestamp; |
885 | 372 |
559
f5f85a07fafe
flags, rounding and cliping fix by (Nathan Kurz <nate at verse dot com>)
michael
parents:
532
diff
changeset
|
373 if (offset > max_offset) offset = max_offset; |
f5f85a07fafe
flags, rounding and cliping fix by (Nathan Kurz <nate at verse dot com>)
michael
parents:
532
diff
changeset
|
374 else if (offset < 0) offset = 0; |
523
d788959a01e2
* seek in raw DV patch by Nathan Kurz (nate at verse dot com)
romansh
parents:
515
diff
changeset
|
375 |
d788959a01e2
* seek in raw DV patch by Nathan Kurz (nate at verse dot com)
romansh
parents:
515
diff
changeset
|
376 return offset; |
392 | 377 } |
378 | |
1629
aedce96c28ff
* Fixing seeking with DV-AVI (by Jeff Downs <heydowns at borg dot com>)
romansh
parents:
1358
diff
changeset
|
379 void dv_offset_reset(DVDemuxContext *c, int64_t frame_offset) |
562
bf3231dd1d7c
* static allocation for audio packets. This will make it a little bit
romansh
parents:
560
diff
changeset
|
380 { |
1629
aedce96c28ff
* Fixing seeking with DV-AVI (by Jeff Downs <heydowns at borg dot com>)
romansh
parents:
1358
diff
changeset
|
381 c->frames= frame_offset; |
aedce96c28ff
* Fixing seeking with DV-AVI (by Jeff Downs <heydowns at borg dot com>)
romansh
parents:
1358
diff
changeset
|
382 if (c->ach) |
aedce96c28ff
* Fixing seeking with DV-AVI (by Jeff Downs <heydowns at borg dot com>)
romansh
parents:
1358
diff
changeset
|
383 c->abytes= av_rescale(c->frames, |
aedce96c28ff
* Fixing seeking with DV-AVI (by Jeff Downs <heydowns at borg dot com>)
romansh
parents:
1358
diff
changeset
|
384 c->ast[0]->codec->bit_rate * (int64_t)c->sys->frame_rate_base, |
aedce96c28ff
* Fixing seeking with DV-AVI (by Jeff Downs <heydowns at borg dot com>)
romansh
parents:
1358
diff
changeset
|
385 8*c->sys->frame_rate); |
562
bf3231dd1d7c
* static allocation for audio packets. This will make it a little bit
romansh
parents:
560
diff
changeset
|
386 c->audio_pkt[0].size = c->audio_pkt[1].size = 0; |
3790
a8a70ae19206
Intial implementation of the DV100 (AKA DVCPRO HD) decoder and demuxer as
romansh
parents:
3787
diff
changeset
|
387 c->audio_pkt[2].size = c->audio_pkt[3].size = 0; |
562
bf3231dd1d7c
* static allocation for audio packets. This will make it a little bit
romansh
parents:
560
diff
changeset
|
388 } |
bf3231dd1d7c
* static allocation for audio packets. This will make it a little bit
romansh
parents:
560
diff
changeset
|
389 |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
390 /************************************************************ |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
391 * Implementation of the easiest DV storage of all -- raw DV. |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
392 ************************************************************/ |
885 | 393 |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
394 typedef struct RawDVContext { |
296
252946de6d3f
* DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents:
288
diff
changeset
|
395 DVDemuxContext* dv_demux; |
995 | 396 uint8_t buf[DV_MAX_FRAME_SIZE]; |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
397 } RawDVContext; |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
398 |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
399 static int dv_read_header(AVFormatContext *s, |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
400 AVFormatParameters *ap) |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
401 { |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
402 RawDVContext *c = s->priv_data; |
995 | 403 |
296
252946de6d3f
* DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents:
288
diff
changeset
|
404 c->dv_demux = dv_init_demux(s); |
524
0b9dfb0cddc8
* misc. fixes and hacks to improve timing detection in raw DV
romansh
parents:
523
diff
changeset
|
405 if (!c->dv_demux) |
0b9dfb0cddc8
* misc. fixes and hacks to improve timing detection in raw DV
romansh
parents:
523
diff
changeset
|
406 return -1; |
885 | 407 |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2274
diff
changeset
|
408 if (get_buffer(s->pb, c->buf, DV_PROFILE_BYTES) <= 0 || |
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2274
diff
changeset
|
409 url_fseek(s->pb, -DV_PROFILE_BYTES, SEEK_CUR) < 0) |
2274
b21c2af60bc9
Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents:
2203
diff
changeset
|
410 return AVERROR(EIO); |
524
0b9dfb0cddc8
* misc. fixes and hacks to improve timing detection in raw DV
romansh
parents:
523
diff
changeset
|
411 |
995 | 412 c->dv_demux->sys = dv_frame_profile(c->buf); |
3790
a8a70ae19206
Intial implementation of the DV100 (AKA DVCPRO HD) decoder and demuxer as
romansh
parents:
3787
diff
changeset
|
413 if (!c->dv_demux->sys) { |
a8a70ae19206
Intial implementation of the DV100 (AKA DVCPRO HD) decoder and demuxer as
romansh
parents:
3787
diff
changeset
|
414 av_log(s, AV_LOG_ERROR, "Can't determine profile of DV input stream.\n"); |
a8a70ae19206
Intial implementation of the DV100 (AKA DVCPRO HD) decoder and demuxer as
romansh
parents:
3787
diff
changeset
|
415 return -1; |
a8a70ae19206
Intial implementation of the DV100 (AKA DVCPRO HD) decoder and demuxer as
romansh
parents:
3787
diff
changeset
|
416 } |
a8a70ae19206
Intial implementation of the DV100 (AKA DVCPRO HD) decoder and demuxer as
romansh
parents:
3787
diff
changeset
|
417 |
995 | 418 s->bit_rate = av_rescale(c->dv_demux->sys->frame_size * 8, |
419 c->dv_demux->sys->frame_rate, | |
420 c->dv_demux->sys->frame_rate_base); | |
885 | 421 |
524
0b9dfb0cddc8
* misc. fixes and hacks to improve timing detection in raw DV
romansh
parents:
523
diff
changeset
|
422 return 0; |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
423 } |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
424 |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
425 |
0 | 426 static int dv_read_packet(AVFormatContext *s, AVPacket *pkt) |
427 { | |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
428 int size; |
885 | 429 RawDVContext *c = s->priv_data; |
430 | |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
431 size = dv_get_packet(c->dv_demux, pkt); |
885 | 432 |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
433 if (size < 0) { |
995 | 434 size = c->dv_demux->sys->frame_size; |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2274
diff
changeset
|
435 if (get_buffer(s->pb, c->buf, size) <= 0) |
2274
b21c2af60bc9
Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents:
2203
diff
changeset
|
436 return AVERROR(EIO); |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
437 |
887 | 438 size = dv_produce_packet(c->dv_demux, pkt, c->buf, size); |
885 | 439 } |
440 | |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
441 return size; |
0 | 442 } |
443 | |
885 | 444 static int dv_read_seek(AVFormatContext *s, int stream_index, |
559
f5f85a07fafe
flags, rounding and cliping fix by (Nathan Kurz <nate at verse dot com>)
michael
parents:
532
diff
changeset
|
445 int64_t timestamp, int flags) |
392 | 446 { |
559
f5f85a07fafe
flags, rounding and cliping fix by (Nathan Kurz <nate at verse dot com>)
michael
parents:
532
diff
changeset
|
447 RawDVContext *r = s->priv_data; |
f5f85a07fafe
flags, rounding and cliping fix by (Nathan Kurz <nate at verse dot com>)
michael
parents:
532
diff
changeset
|
448 DVDemuxContext *c = r->dv_demux; |
f5f85a07fafe
flags, rounding and cliping fix by (Nathan Kurz <nate at verse dot com>)
michael
parents:
532
diff
changeset
|
449 int64_t offset= dv_frame_offset(s, c, timestamp, flags); |
392 | 450 |
1629
aedce96c28ff
* Fixing seeking with DV-AVI (by Jeff Downs <heydowns at borg dot com>)
romansh
parents:
1358
diff
changeset
|
451 dv_offset_reset(c, offset / c->sys->frame_size); |
885 | 452 |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2274
diff
changeset
|
453 offset = url_fseek(s->pb, offset, SEEK_SET); |
2203
a81bd08b5ff2
* clarifying the AVInputFormat::read_seek return value
romansh
parents:
1629
diff
changeset
|
454 return (offset < 0)?offset:0; |
392 | 455 } |
456 | |
0 | 457 static int dv_read_close(AVFormatContext *s) |
458 { | |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
459 RawDVContext *c = s->priv_data; |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
460 av_free(c->dv_demux); |
0 | 461 return 0; |
462 } | |
463 | |
1169 | 464 #ifdef CONFIG_DV_DEMUXER |
465 AVInputFormat dv_demuxer = { | |
0 | 466 "dv", |
3424
7a0230981402
Make long_names in lavf/lavdev optional depending on CONFIG_SMALL.
diego
parents:
3286
diff
changeset
|
467 NULL_IF_CONFIG_SMALL("DV video format"), |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
468 sizeof(RawDVContext), |
0 | 469 NULL, |
470 dv_read_header, | |
471 dv_read_packet, | |
472 dv_read_close, | |
392 | 473 dv_read_seek, |
393 | 474 .extensions = "dv,dif", |
0 | 475 }; |
1169 | 476 #endif |