Mercurial > libavformat.hg
annotate dv.c @ 1282:faf64f0d3445 libavformat
AVISynth support, patch by Steve Lhomme % slhomme A divxcorp P com %
Original Thread:
Date: Aug 16, 2006 11:45 PM
Subject: [Ffmpeg-devel] [PATCH] AVISynth support
author | gpoirier |
---|---|
date | Tue, 29 Aug 2006 07:34:58 +0000 |
parents | d18cc9a1fd02 |
children | 6db39fb15d60 |
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 * | |
995 | 11 * 50 Mbps (DVCPRO50) support |
12 * Copyright (c) 2006 Daniel Maas <dmaas@maasdigital.com> | |
13 * | |
0 | 14 * This library is free software; you can redistribute it and/or |
15 * modify it under the terms of the GNU Lesser General Public | |
16 * License as published by the Free Software Foundation; either | |
17 * version 2 of the License, or (at your option) any later version. | |
18 * | |
19 * This library is distributed in the hope that it will be useful, | |
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
22 * Lesser General Public License for more details. | |
23 * | |
24 * You should have received a copy of the GNU Lesser General Public | |
25 * License along with this library; if not, write to the Free Software | |
896
edbe5c3717f9
Update licensing information: The FSF changed postal address.
diego
parents:
887
diff
changeset
|
26 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
0 | 27 */ |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
28 #include <time.h> |
0 | 29 #include "avformat.h" |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
30 #include "dvdata.h" |
296
252946de6d3f
* DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents:
288
diff
changeset
|
31 #include "dv.h" |
0 | 32 |
296
252946de6d3f
* DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents:
288
diff
changeset
|
33 struct DVDemuxContext { |
995 | 34 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
|
35 AVFormatContext* fctx; |
252946de6d3f
* DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents:
288
diff
changeset
|
36 AVStream* vst; |
885 | 37 AVStream* ast[2]; |
296
252946de6d3f
* DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents:
288
diff
changeset
|
38 AVPacket audio_pkt[2]; |
562
bf3231dd1d7c
* static allocation for audio packets. This will make it a little bit
romansh
parents:
560
diff
changeset
|
39 uint8_t audio_buf[2][8192]; |
296
252946de6d3f
* DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents:
288
diff
changeset
|
40 int ach; |
392 | 41 int frames; |
42 uint64_t abytes; | |
296
252946de6d3f
* DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents:
288
diff
changeset
|
43 }; |
0 | 44 |
296
252946de6d3f
* DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents:
288
diff
changeset
|
45 struct DVMuxContext { |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
46 const DVprofile* sys; /* Current DV profile. E.g.: 525/60, 625/50 */ |
995 | 47 int n_ast; /* Number of stereo audio streams (up to 2) */ |
48 AVStream *ast[2]; /* Stereo audio streams */ | |
49 FifoBuffer audio_data[2]; /* Fifo for storing excessive amounts of PCM */ | |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
50 int frames; /* Number of a current frame */ |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
51 time_t start_time; /* Start time of recording */ |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
52 uint8_t aspect; /* Aspect ID 0 - 4:3, 7 - 16:9 */ |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
53 int has_audio; /* frame under contruction has audio */ |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
54 int has_video; /* frame under contruction has video */ |
995 | 55 uint8_t frame_buf[DV_MAX_FRAME_SIZE]; /* frame under contruction */ |
296
252946de6d3f
* DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents:
288
diff
changeset
|
56 }; |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
57 |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
58 enum dv_section_type { |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
59 dv_sect_header = 0x1f, |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
60 dv_sect_subcode = 0x3f, |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
61 dv_sect_vaux = 0x56, |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
62 dv_sect_audio = 0x76, |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
63 dv_sect_video = 0x96, |
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 |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
66 enum dv_pack_type { |
885 | 67 dv_header525 = 0x3f, /* see dv_write_pack for important details on */ |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
68 dv_header625 = 0xbf, /* these two packs */ |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
69 dv_timecode = 0x13, |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
70 dv_audio_source = 0x50, |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
71 dv_audio_control = 0x51, |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
72 dv_audio_recdate = 0x52, |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
73 dv_audio_rectime = 0x53, |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
74 dv_video_source = 0x60, |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
75 dv_video_control = 0x61, |
848 | 76 dv_video_recdate = 0x62, |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
77 dv_video_rectime = 0x63, |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
78 dv_unknown_pack = 0xff, |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
79 }; |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
80 |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
81 |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
82 |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
83 /* |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
84 * The reason why the following three big ugly looking tables are |
885 | 85 * here is my lack of DV spec IEC 61834. The tables were basically |
86 * constructed to make code that places packs in SSYB, VAUX and | |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
87 * AAUX blocks very simple and table-driven. They conform to the |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
88 * SMPTE 314M and the output of my personal DV camcorder, neither |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
89 * of which is sufficient for a reliable DV stream producing. Thus |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
90 * while code is still in development I'll be gathering input from |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
91 * people with different DV equipment and modifying the tables to |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
92 * accommodate all the quirks. Later on, if possible, some of them |
885 | 93 * will be folded into smaller tables and/or switch-if logic. For |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
94 * now, my only excuse is -- they don't eat up that much of a space. |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
95 */ |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
96 |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
97 static const int dv_ssyb_packs_dist[12][6] = { |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
98 { 0x13, 0x13, 0x13, 0x13, 0x13, 0x13 }, |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
99 { 0x13, 0x13, 0x13, 0x13, 0x13, 0x13 }, |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
100 { 0x13, 0x13, 0x13, 0x13, 0x13, 0x13 }, |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
101 { 0x13, 0x13, 0x13, 0x13, 0x13, 0x13 }, |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
102 { 0x13, 0x13, 0x13, 0x13, 0x13, 0x13 }, |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
103 { 0x13, 0x13, 0x13, 0x13, 0x13, 0x13 }, |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
104 { 0x13, 0x62, 0x63, 0x13, 0x62, 0x63 }, |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
105 { 0x13, 0x62, 0x63, 0x13, 0x62, 0x63 }, |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
106 { 0x13, 0x62, 0x63, 0x13, 0x62, 0x63 }, |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
107 { 0x13, 0x62, 0x63, 0x13, 0x62, 0x63 }, |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
108 { 0x13, 0x62, 0x63, 0x13, 0x62, 0x63 }, |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
109 { 0x13, 0x62, 0x63, 0x13, 0x62, 0x63 }, |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
110 }; |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
111 |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
112 static const int dv_vaux_packs_dist[12][15] = { |
885 | 113 { 0x60, 0x61, 0x62, 0x63, 0xff, 0xff, 0xff, 0xff, 0xff, |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
114 0x60, 0x61, 0x62, 0x63, 0xff, 0xff }, |
885 | 115 { 0x60, 0x61, 0x62, 0x63, 0xff, 0xff, 0xff, 0xff, 0xff, |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
116 0x60, 0x61, 0x62, 0x63, 0xff, 0xff }, |
885 | 117 { 0x60, 0x61, 0x62, 0x63, 0xff, 0xff, 0xff, 0xff, 0xff, |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
118 0x60, 0x61, 0x62, 0x63, 0xff, 0xff }, |
885 | 119 { 0x60, 0x61, 0x62, 0x63, 0xff, 0xff, 0xff, 0xff, 0xff, |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
120 0x60, 0x61, 0x62, 0x63, 0xff, 0xff }, |
885 | 121 { 0x60, 0x61, 0x62, 0x63, 0xff, 0xff, 0xff, 0xff, 0xff, |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
122 0x60, 0x61, 0x62, 0x63, 0xff, 0xff }, |
885 | 123 { 0x60, 0x61, 0x62, 0x63, 0xff, 0xff, 0xff, 0xff, 0xff, |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
124 0x60, 0x61, 0x62, 0x63, 0xff, 0xff }, |
885 | 125 { 0x60, 0x61, 0x62, 0x63, 0xff, 0xff, 0xff, 0xff, 0xff, |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
126 0x60, 0x61, 0x62, 0x63, 0xff, 0xff }, |
885 | 127 { 0x60, 0x61, 0x62, 0x63, 0xff, 0xff, 0xff, 0xff, 0xff, |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
128 0x60, 0x61, 0x62, 0x63, 0xff, 0xff }, |
885 | 129 { 0x60, 0x61, 0x62, 0x63, 0xff, 0xff, 0xff, 0xff, 0xff, |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
130 0x60, 0x61, 0x62, 0x63, 0xff, 0xff }, |
885 | 131 { 0x60, 0x61, 0x62, 0x63, 0xff, 0xff, 0xff, 0xff, 0xff, |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
132 0x60, 0x61, 0x62, 0x63, 0xff, 0xff }, |
885 | 133 { 0x60, 0x61, 0x62, 0x63, 0xff, 0xff, 0xff, 0xff, 0xff, |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
134 0x60, 0x61, 0x62, 0x63, 0xff, 0xff }, |
885 | 135 { 0x60, 0x61, 0x62, 0x63, 0xff, 0xff, 0xff, 0xff, 0xff, |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
136 0x60, 0x61, 0x62, 0x63, 0xff, 0xff }, |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
137 }; |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
138 |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
139 static const int dv_aaux_packs_dist[12][9] = { |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
140 { 0xff, 0xff, 0xff, 0x50, 0x51, 0x52, 0x53, 0xff, 0xff }, |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
141 { 0x50, 0x51, 0x52, 0x53, 0xff, 0xff, 0xff, 0xff, 0xff }, |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
142 { 0xff, 0xff, 0xff, 0x50, 0x51, 0x52, 0x53, 0xff, 0xff }, |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
143 { 0x50, 0x51, 0x52, 0x53, 0xff, 0xff, 0xff, 0xff, 0xff }, |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
144 { 0xff, 0xff, 0xff, 0x50, 0x51, 0x52, 0x53, 0xff, 0xff }, |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
145 { 0x50, 0x51, 0x52, 0x53, 0xff, 0xff, 0xff, 0xff, 0xff }, |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
146 { 0xff, 0xff, 0xff, 0x50, 0x51, 0x52, 0x53, 0xff, 0xff }, |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
147 { 0x50, 0x51, 0x52, 0x53, 0xff, 0xff, 0xff, 0xff, 0xff }, |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
148 { 0xff, 0xff, 0xff, 0x50, 0x51, 0x52, 0x53, 0xff, 0xff }, |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
149 { 0x50, 0x51, 0x52, 0x53, 0xff, 0xff, 0xff, 0xff, 0xff }, |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
150 { 0xff, 0xff, 0xff, 0x50, 0x51, 0x52, 0x53, 0xff, 0xff }, |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
151 { 0x50, 0x51, 0x52, 0x53, 0xff, 0xff, 0xff, 0xff, 0xff }, |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
152 }; |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
153 |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
154 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
|
155 { |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
156 uint16_t shift, result; |
885 | 157 |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
158 sample = (sample < 0x800) ? sample : sample | 0xf000; |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
159 shift = (sample & 0xf00) >> 8; |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
160 |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
161 if (shift < 0x2 || shift > 0xd) { |
887 | 162 result = sample; |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
163 } else if (shift < 0x8) { |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
164 shift--; |
887 | 165 result = (sample - (256 * shift)) << shift; |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
166 } else { |
887 | 167 shift = 0xe - shift; |
168 result = ((sample + ((256 * shift) + 1)) << shift) - 1; | |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
169 } |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
170 |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
171 return result; |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
172 } |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
173 |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
174 static int dv_audio_frame_size(const DVprofile* sys, int frame) |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
175 { |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
176 return sys->audio_samples_dist[frame % (sizeof(sys->audio_samples_dist)/ |
887 | 177 sizeof(sys->audio_samples_dist[0]))]; |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
178 } |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
179 |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
180 static int dv_write_pack(enum dv_pack_type pack_id, DVMuxContext *c, uint8_t* buf) |
0 | 181 { |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
182 struct tm tc; |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
183 time_t ct; |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
184 int ltc_frame; |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
185 |
995 | 186 /* Its hard to tell what SMPTE requires w.r.t. APT, but Quicktime needs it. |
187 * We set it based on pix_fmt value but it really should be per DV profile */ | |
188 int apt = (c->sys->pix_fmt == PIX_FMT_YUV422P ? 1 : 0); | |
189 | |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
190 buf[0] = (uint8_t)pack_id; |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
191 switch (pack_id) { |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
192 case dv_header525: /* I can't imagine why these two weren't defined as real */ |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
193 case dv_header625: /* packs in SMPTE314M -- they definitely look like ones */ |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
194 buf[1] = 0xf8 | /* reserved -- always 1 */ |
995 | 195 (apt & 0x07); /* APT: Track application ID */ |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
196 buf[2] = (0 << 7) | /* TF1: audio data is 0 - valid; 1 - invalid */ |
887 | 197 (0x0f << 3) | /* reserved -- always 1 */ |
995 | 198 (apt & 0x07); /* AP1: Audio application ID */ |
885 | 199 buf[3] = (0 << 7) | /* TF2: video data is 0 - valid; 1 - invalid */ |
887 | 200 (0x0f << 3) | /* reserved -- always 1 */ |
995 | 201 (apt & 0x07); /* AP2: Video application ID */ |
885 | 202 buf[4] = (0 << 7) | /* TF3: subcode(SSYB) is 0 - valid; 1 - invalid */ |
887 | 203 (0x0f << 3) | /* reserved -- always 1 */ |
995 | 204 (apt & 0x07); /* AP3: Subcode application ID */ |
887 | 205 break; |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
206 case dv_timecode: |
885 | 207 ct = (time_t)(c->frames / ((float)c->sys->frame_rate / |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
208 (float)c->sys->frame_rate_base)); |
515
ad72189eec07
* replacing calls to not-always-available gmtime_r with our own code.
romansh
parents:
508
diff
changeset
|
209 brktimegm(ct, &tc); |
885 | 210 /* |
211 * LTC drop-frame frame counter drops two frames (0 and 1) every | |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
212 * minute, unless it is exactly divisible by 10 |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
213 */ |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
214 ltc_frame = (c->frames + 2*ct/60 - 2*ct/600) % c->sys->ltc_divisor; |
887 | 215 buf[1] = (0 << 7) | /* Color fame: 0 - unsync; 1 - sync mode */ |
216 (1 << 6) | /* Drop frame timecode: 0 - nondrop; 1 - drop */ | |
217 ((ltc_frame / 10) << 4) | /* Tens of frames */ | |
218 (ltc_frame % 10); /* Units of frames */ | |
219 buf[2] = (1 << 7) | /* Biphase mark polarity correction: 0 - even; 1 - odd */ | |
220 ((tc.tm_sec / 10) << 4) | /* Tens of seconds */ | |
221 (tc.tm_sec % 10); /* Units of seconds */ | |
222 buf[3] = (1 << 7) | /* Binary group flag BGF0 */ | |
223 ((tc.tm_min / 10) << 4) | /* Tens of minutes */ | |
224 (tc.tm_min % 10); /* Units of minutes */ | |
225 buf[4] = (1 << 7) | /* Binary group flag BGF2 */ | |
226 (1 << 6) | /* Binary group flag BGF1 */ | |
227 ((tc.tm_hour / 10) << 4) | /* Tens of hours */ | |
228 (tc.tm_hour % 10); /* Units of hours */ | |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
229 break; |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
230 case dv_audio_source: /* AAUX source pack */ |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
231 buf[1] = (0 << 7) | /* locked mode */ |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
232 (1 << 6) | /* reserved -- always 1 */ |
887 | 233 (dv_audio_frame_size(c->sys, c->frames) - |
234 c->sys->audio_min_samples[0]); | |
235 /* # of samples */ | |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
236 buf[2] = (0 << 7) | /* multi-stereo */ |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
237 (0 << 5) | /* #of audio channels per block: 0 -- 1 channel */ |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
238 (0 << 4) | /* pair bit: 0 -- one pair of channels */ |
887 | 239 0; /* audio mode */ |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
240 buf[3] = (1 << 7) | /* res */ |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
241 (1 << 6) | /* multi-language flag */ |
887 | 242 (c->sys->dsf << 5) | /* system: 60fields/50fields */ |
995 | 243 (apt << 1);/* definition: 0 -- 25Mbps, 2 -- 50Mbps */ |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
244 buf[4] = (1 << 7) | /* emphasis: 1 -- off */ |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
245 (0 << 6) | /* emphasis time constant: 0 -- reserved */ |
887 | 246 (0 << 3) | /* frequency: 0 -- 48Khz, 1 -- 44,1Khz, 2 -- 32Khz */ |
885 | 247 0; /* quantization: 0 -- 16bit linear, 1 -- 12bit nonlinear */ |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
248 break; |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
249 case dv_audio_control: |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
250 buf[1] = (0 << 6) | /* copy protection: 0 -- unrestricted */ |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
251 (1 << 4) | /* input source: 1 -- digital input */ |
887 | 252 (3 << 2) | /* compression: 3 -- no information */ |
253 0; /* misc. info/SMPTE emphasis off */ | |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
254 buf[2] = (1 << 7) | /* recording start point: 1 -- no */ |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
255 (1 << 6) | /* recording end point: 1 -- no */ |
887 | 256 (1 << 3) | /* recording mode: 1 -- original */ |
257 7; | |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
258 buf[3] = (1 << 7) | /* direction: 1 -- forward */ |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
259 0x20; /* speed */ |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
260 buf[4] = (1 << 7) | /* reserved -- always 1 */ |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
261 0x7f; /* genre category */ |
887 | 262 break; |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
263 case dv_audio_recdate: |
848 | 264 case dv_video_recdate: /* VAUX recording date */ |
885 | 265 ct = c->start_time + (time_t)(c->frames / |
887 | 266 ((float)c->sys->frame_rate / (float)c->sys->frame_rate_base)); |
515
ad72189eec07
* replacing calls to not-always-available gmtime_r with our own code.
romansh
parents:
508
diff
changeset
|
267 brktimegm(ct, &tc); |
887 | 268 buf[1] = 0xff; /* ds, tm, tens of time zone, units of time zone */ |
269 /* 0xff is very likely to be "unknown" */ | |
270 buf[2] = (3 << 6) | /* reserved -- always 1 */ | |
271 ((tc.tm_mday / 10) << 4) | /* Tens of day */ | |
272 (tc.tm_mday % 10); /* Units of day */ | |
273 buf[3] = /* we set high 4 bits to 0, shouldn't we set them to week? */ | |
274 ((tc.tm_mon / 10) << 4) | /* Tens of month */ | |
275 (tc.tm_mon % 10); /* Units of month */ | |
276 buf[4] = (((tc.tm_year % 100) / 10) << 4) | /* Tens of year */ | |
277 (tc.tm_year % 10); /* Units of year */ | |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
278 break; |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
279 case dv_audio_rectime: /* AAUX recording time */ |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
280 case dv_video_rectime: /* VAUX recording time */ |
885 | 281 ct = c->start_time + (time_t)(c->frames / |
887 | 282 ((float)c->sys->frame_rate / (float)c->sys->frame_rate_base)); |
283 brktimegm(ct, &tc); | |
284 buf[1] = (3 << 6) | /* reserved -- always 1 */ | |
285 0x3f; /* tens of frame, units of frame: 0x3f - "unknown" ? */ | |
286 buf[2] = (1 << 7) | /* reserved -- always 1 */ | |
287 ((tc.tm_sec / 10) << 4) | /* Tens of seconds */ | |
288 (tc.tm_sec % 10); /* Units of seconds */ | |
289 buf[3] = (1 << 7) | /* reserved -- always 1 */ | |
290 ((tc.tm_min / 10) << 4) | /* Tens of minutes */ | |
291 (tc.tm_min % 10); /* Units of minutes */ | |
292 buf[4] = (3 << 6) | /* reserved -- always 1 */ | |
293 ((tc.tm_hour / 10) << 4) | /* Tens of hours */ | |
294 (tc.tm_hour % 10); /* Units of hours */ | |
295 break; | |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
296 case dv_video_source: |
887 | 297 buf[1] = 0xff; /* reserved -- always 1 */ |
298 buf[2] = (1 << 7) | /* B/W: 0 - b/w, 1 - color */ | |
299 (1 << 6) | /* following CLF is valid - 0, invalid - 1 */ | |
300 (3 << 4) | /* CLF: color frames id (see ITU-R BT.470-4) */ | |
301 0xf; /* reserved -- always 1 */ | |
302 buf[3] = (3 << 6) | /* reserved -- always 1 */ | |
303 (c->sys->dsf << 5) | /* system: 60fields/50fields */ | |
995 | 304 (apt << 2); /* signal type video compression */ |
887 | 305 buf[4] = 0xff; /* VISC: 0xff -- no information */ |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
306 break; |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
307 case dv_video_control: |
887 | 308 buf[1] = (0 << 6) | /* Copy generation management (CGMS) 0 -- free */ |
309 0x3f; /* reserved -- always 1 */ | |
310 buf[2] = 0xc8 | /* reserved -- always b11001xxx */ | |
311 c->aspect; | |
312 buf[3] = (1 << 7) | /* Frame/field flag 1 -- frame, 0 -- field */ | |
313 (1 << 6) | /* First/second field flag 0 -- field 2, 1 -- field 1 */ | |
314 (1 << 5) | /* Frame change flag 0 -- same picture as before, 1 -- different */ | |
315 (1 << 4) | /* 1 - interlaced, 0 - noninterlaced */ | |
316 0xc; /* reserved -- always b1100 */ | |
317 buf[4] = 0xff; /* reserved -- always 1 */ | |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
318 break; |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
319 default: |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
320 buf[1] = buf[2] = buf[3] = buf[4] = 0xff; |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
321 } |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
322 return 5; |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
323 } |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
324 |
995 | 325 static inline int dv_write_dif_id(enum dv_section_type t, uint8_t chan_num, uint8_t seq_num, |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
326 uint8_t dif_num, uint8_t* buf) |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
327 { |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
328 buf[0] = (uint8_t)t; /* Section type */ |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
329 buf[1] = (seq_num<<4) | /* DIF seq number 0-9 for 525/60; 0-11 for 625/50 */ |
995 | 330 (chan_num << 3) | /* FSC: for 50Mb/s 0 - first channel; 1 - second */ |
887 | 331 7; /* reserved -- always 1 */ |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
332 buf[2] = dif_num; /* DIF block number Video: 0-134, Audio: 0-8 */ |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
333 return 3; |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
334 } |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
335 |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
336 static inline int dv_write_ssyb_id(uint8_t syb_num, uint8_t fr, uint8_t* buf) |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
337 { |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
338 if (syb_num == 0 || syb_num == 6) { |
887 | 339 buf[0] = (fr<<7) | /* FR ID 1 - first half of each channel; 0 - second */ |
340 (0<<4) | /* AP3 (Subcode application ID) */ | |
341 0x0f; /* reserved -- always 1 */ | |
885 | 342 } |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
343 else if (syb_num == 11) { |
887 | 344 buf[0] = (fr<<7) | /* FR ID 1 - first half of each channel; 0 - second */ |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
345 0x7f; /* reserved -- always 1 */ |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
346 } |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
347 else { |
887 | 348 buf[0] = (fr<<7) | /* FR ID 1 - first half of each channel; 0 - second */ |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
349 (0<<4) | /* APT (Track application ID) */ |
887 | 350 0x0f; /* reserved -- always 1 */ |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
351 } |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
352 buf[1] = 0xf0 | /* reserved -- always 1 */ |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
353 (syb_num & 0x0f); /* SSYB number 0 - 11 */ |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
354 buf[2] = 0xff; /* reserved -- always 1 */ |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
355 return 3; |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
356 } |
0 | 357 |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
358 static void dv_format_frame(DVMuxContext *c, uint8_t* buf) |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
359 { |
995 | 360 int chan, i, j, k; |
885 | 361 |
995 | 362 for (chan = 0; chan < c->sys->n_difchan; chan++) { |
363 for (i = 0; i < c->sys->difseg_size; i++) { | |
364 memset(buf, 0xff, 80 * 6); /* First 6 DIF blocks are for control data */ | |
885 | 365 |
995 | 366 /* DV header: 1DIF */ |
367 buf += dv_write_dif_id(dv_sect_header, chan, i, 0, buf); | |
368 buf += dv_write_pack((c->sys->dsf ? dv_header625 : dv_header525), c, buf); | |
369 buf += 72; /* unused bytes */ | |
370 | |
371 /* DV subcode: 2DIFs */ | |
372 for (j = 0; j < 2; j++) { | |
373 buf += dv_write_dif_id(dv_sect_subcode, chan, i, j, buf); | |
374 for (k = 0; k < 6; k++) { | |
375 buf += dv_write_ssyb_id(k, (i < c->sys->difseg_size/2), buf); | |
376 buf += dv_write_pack(dv_ssyb_packs_dist[i][k], c, buf); | |
377 } | |
378 buf += 29; /* unused bytes */ | |
379 } | |
885 | 380 |
995 | 381 /* DV VAUX: 3DIFs */ |
382 for (j = 0; j < 3; j++) { | |
383 buf += dv_write_dif_id(dv_sect_vaux, chan, i, j, buf); | |
384 for (k = 0; k < 15 ; k++) | |
385 buf += dv_write_pack(dv_vaux_packs_dist[i][k], c, buf); | |
386 buf += 2; /* unused bytes */ | |
387 } | |
885 | 388 |
995 | 389 /* DV Audio/Video: 135 Video DIFs + 9 Audio DIFs */ |
390 for (j = 0; j < 135; j++) { | |
391 if (j%15 == 0) { | |
392 memset(buf, 0xff, 80); | |
393 buf += dv_write_dif_id(dv_sect_audio, chan, i, j/15, buf); | |
394 buf += 77; /* audio control & shuffled PCM audio */ | |
395 } | |
396 buf += dv_write_dif_id(dv_sect_video, chan, i, j, buf); | |
397 buf += 77; /* 1 video macro block: 1 bytes control | |
398 4 * 14 bytes Y 8x8 data | |
399 10 bytes Cr 8x8 data | |
400 10 bytes Cb 8x8 data */ | |
887 | 401 } |
995 | 402 } |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
403 } |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
404 } |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
405 |
995 | 406 static void dv_inject_audio(DVMuxContext *c, const uint8_t* pcm, int channel, uint8_t* frame_ptr) |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
407 { |
504 | 408 int i, j, d, of, size; |
409 size = 4 * dv_audio_frame_size(c->sys, c->frames); | |
995 | 410 frame_ptr += channel * c->sys->difseg_size * 150 * 80; |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
411 for (i = 0; i < c->sys->difseg_size; i++) { |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
412 frame_ptr += 6 * 80; /* skip DIF segment header */ |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
413 for (j = 0; j < 9; j++) { |
887 | 414 dv_write_pack(dv_aaux_packs_dist[i][j], c, &frame_ptr[3]); |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
415 for (d = 8; d < 80; d+=2) { |
887 | 416 of = c->sys->audio_shuffle[i][j] + (d - 8)/2 * c->sys->audio_stride; |
417 if (of*2 >= size) | |
418 continue; | |
885 | 419 |
887 | 420 frame_ptr[d] = pcm[of*2+1]; // FIXME: may be we have to admit |
421 frame_ptr[d+1] = pcm[of*2]; // that DV is a big endian PCM | |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
422 } |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
423 frame_ptr += 16 * 80; /* 15 Video DIFs + 1 Audio DIF */ |
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 } |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
426 } |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
427 |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
428 static void dv_inject_video(DVMuxContext *c, const uint8_t* video_data, uint8_t* frame_ptr) |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
429 { |
995 | 430 int chan, i, j; |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
431 int ptr = 0; |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
432 |
995 | 433 for (chan = 0; chan < c->sys->n_difchan; chan++) { |
434 for (i = 0; i < c->sys->difseg_size; i++) { | |
435 ptr += 6 * 80; /* skip DIF segment header */ | |
436 for (j = 0; j < 135; j++) { | |
437 if (j%15 == 0) | |
438 ptr += 80; /* skip Audio DIF */ | |
439 ptr += 3; | |
440 memcpy(frame_ptr + ptr, video_data + ptr, 77); | |
441 ptr += 77; | |
442 } | |
443 } | |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
444 } |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
445 } |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
446 |
885 | 447 /* |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
448 * 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
|
449 * 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
|
450 * 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
|
451 */ |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
452 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
|
453 { |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
454 int offs; |
885 | 455 |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
456 switch (t) { |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
457 case dv_audio_source: |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
458 offs = (80*6 + 80*16*3 + 3); |
887 | 459 break; |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
460 case dv_audio_control: |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
461 offs = (80*6 + 80*16*4 + 3); |
887 | 462 break; |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
463 case dv_video_control: |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
464 offs = (80*5 + 48 + 5); |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
465 break; |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
466 default: |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
467 return NULL; |
885 | 468 } |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
469 |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
470 return (frame[offs] == t ? &frame[offs] : NULL); |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
471 } |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
472 |
885 | 473 /* |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
474 * There's a couple of assumptions being made here: |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
475 * 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
|
476 * 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
|
477 * 2. We don't do software emphasis. |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
478 * 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
|
479 * are converted into 16bit linear ones. |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
480 */ |
995 | 481 static int dv_extract_audio(uint8_t* frame, uint8_t* pcm, uint8_t* pcm2, |
482 const DVprofile *sys) | |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
483 { |
995 | 484 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
|
485 uint16_t lc, rc; |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
486 const uint8_t* as_pack; |
885 | 487 |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
488 as_pack = dv_extract_pack(frame, dv_audio_source); |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
489 if (!as_pack) /* No audio ? */ |
887 | 490 return 0; |
885 | 491 |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
492 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
|
493 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
|
494 quant = as_pack[4] & 0x07; /* 0 - 16bit linear, 1 - 12bit nonlinear */ |
885 | 495 |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
496 if (quant > 1) |
887 | 497 return -1; /* Unsupported quantization */ |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
498 |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
499 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
|
500 half_ch = sys->difseg_size/2; |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
501 |
995 | 502 /* for each DIF channel */ |
503 for (chan = 0; chan < sys->n_difchan; chan++) { | |
504 /* for each DIF segment */ | |
505 for (i = 0; i < sys->difseg_size; i++) { | |
506 frame += 6 * 80; /* skip DIF segment header */ | |
507 if (quant == 1 && i == half_ch) { | |
508 /* next stereo channel (12bit mode only) */ | |
509 if (!pcm2) | |
510 break; | |
511 else | |
512 pcm = pcm2; | |
513 } | |
296
252946de6d3f
* DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents:
288
diff
changeset
|
514 |
995 | 515 /* for each AV sequence */ |
516 for (j = 0; j < 9; j++) { | |
517 for (d = 8; d < 80; d += 2) { | |
518 if (quant == 0) { /* 16bit quantization */ | |
519 of = sys->audio_shuffle[i][j] + (d - 8)/2 * sys->audio_stride; | |
520 if (of*2 >= size) | |
521 continue; | |
885 | 522 |
995 | 523 pcm[of*2] = frame[d+1]; // FIXME: may be we have to admit |
524 pcm[of*2+1] = frame[d]; // that DV is a big endian PCM | |
525 if (pcm[of*2+1] == 0x80 && pcm[of*2] == 0x00) | |
526 pcm[of*2+1] = 0; | |
527 } else { /* 12bit quantization */ | |
528 lc = ((uint16_t)frame[d] << 4) | | |
529 ((uint16_t)frame[d+2] >> 4); | |
530 rc = ((uint16_t)frame[d+1] << 4) | | |
531 ((uint16_t)frame[d+2] & 0x0f); | |
532 lc = (lc == 0x800 ? 0 : dv_audio_12to16(lc)); | |
533 rc = (rc == 0x800 ? 0 : dv_audio_12to16(rc)); | |
534 | |
535 of = sys->audio_shuffle[i%half_ch][j] + (d - 8)/3 * sys->audio_stride; | |
536 if (of*2 >= size) | |
537 continue; | |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
538 |
995 | 539 pcm[of*2] = lc & 0xff; // FIXME: may be we have to admit |
540 pcm[of*2+1] = lc >> 8; // that DV is a big endian PCM | |
541 of = sys->audio_shuffle[i%half_ch+half_ch][j] + | |
542 (d - 8)/3 * sys->audio_stride; | |
543 pcm[of*2] = rc & 0xff; // FIXME: may be we have to admit | |
544 pcm[of*2+1] = rc >> 8; // that DV is a big endian PCM | |
545 ++d; | |
546 } | |
547 } | |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
548 |
995 | 549 frame += 16 * 80; /* 15 Video DIFs + 1 Audio DIF */ |
550 } | |
551 } | |
885 | 552 |
995 | 553 /* next stereo channel (50Mbps only) */ |
554 if(!pcm2) | |
555 break; | |
556 pcm = pcm2; | |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
557 } |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
558 |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
559 return size; |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
560 } |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
561 |
296
252946de6d3f
* DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents:
288
diff
changeset
|
562 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
|
563 { |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
564 const uint8_t* as_pack; |
995 | 565 int freq, stype, smpls, quant, i, ach; |
37 | 566 |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
567 as_pack = dv_extract_pack(frame, dv_audio_source); |
995 | 568 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
|
569 c->ach = 0; |
887 | 570 return 0; |
296
252946de6d3f
* DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents:
288
diff
changeset
|
571 } |
885 | 572 |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
573 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
|
574 freq = (as_pack[4] >> 3) & 0x07; /* 0 - 48KHz, 1 - 44,1kHz, 2 - 32 kHz */ |
995 | 575 stype = (as_pack[3] & 0x1f); /* 0 - 2CH, 2 - 4CH */ |
296
252946de6d3f
* DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents:
288
diff
changeset
|
576 quant = as_pack[4] & 0x07; /* 0 - 16bit linear, 1 - 12bit nonlinear */ |
995 | 577 |
578 /* note: ach counts PAIRS of channels (i.e. stereo channels) */ | |
579 ach = (stype == 2 || (quant && (freq == 2))) ? 2 : 1; | |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
580 |
532
772247018ade
* experimental dynamic audio stream allocation for DV demuxer. This
romansh
parents:
531
diff
changeset
|
581 /* Dynamic handling of the audio streams in DV */ |
772247018ade
* experimental dynamic audio stream allocation for DV demuxer. This
romansh
parents:
531
diff
changeset
|
582 for (i=0; i<ach; i++) { |
772247018ade
* experimental dynamic audio stream allocation for DV demuxer. This
romansh
parents:
531
diff
changeset
|
583 if (!c->ast[i]) { |
772247018ade
* experimental dynamic audio stream allocation for DV demuxer. This
romansh
parents:
531
diff
changeset
|
584 c->ast[i] = av_new_stream(c->fctx, 0); |
887 | 585 if (!c->ast[i]) |
586 break; | |
587 av_set_pts_info(c->ast[i], 64, 1, 30000); | |
588 c->ast[i]->codec->codec_type = CODEC_TYPE_AUDIO; | |
589 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
|
590 |
bf3231dd1d7c
* static allocation for audio packets. This will make it a little bit
romansh
parents:
560
diff
changeset
|
591 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
|
592 c->audio_pkt[i].size = 0; |
bf3231dd1d7c
* static allocation for audio packets. This will make it a little bit
romansh
parents:
560
diff
changeset
|
593 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
|
594 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
|
595 c->audio_pkt[i].flags |= PKT_FLAG_KEY; |
532
772247018ade
* experimental dynamic audio stream allocation for DV demuxer. This
romansh
parents:
531
diff
changeset
|
596 } |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
764
diff
changeset
|
597 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
|
598 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
|
599 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
|
600 c->ast[i]->start_time = 0; |
296
252946de6d3f
* DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents:
288
diff
changeset
|
601 } |
532
772247018ade
* experimental dynamic audio stream allocation for DV demuxer. This
romansh
parents:
531
diff
changeset
|
602 c->ach = i; |
885 | 603 |
995 | 604 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
|
605 } |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
606 |
296
252946de6d3f
* DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents:
288
diff
changeset
|
607 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
|
608 { |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
609 const uint8_t* vsc_pack; |
296
252946de6d3f
* DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents:
288
diff
changeset
|
610 AVCodecContext* avctx; |
252946de6d3f
* DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents:
288
diff
changeset
|
611 int apt, is16_9; |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
612 int size = 0; |
885 | 613 |
995 | 614 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
|
615 avctx = c->vst->codec; |
885 | 616 |
995 | 617 av_set_pts_info(c->vst, 64, c->sys->frame_rate_base, c->sys->frame_rate); |
618 avctx->time_base= (AVRational){c->sys->frame_rate_base, c->sys->frame_rate}; | |
845 | 619 if(!avctx->width){ |
995 | 620 avctx->width = c->sys->width; |
621 avctx->height = c->sys->height; | |
845 | 622 } |
995 | 623 avctx->pix_fmt = c->sys->pix_fmt; |
885 | 624 |
887 | 625 /* finding out SAR is a little bit messy */ |
626 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
|
627 apt = frame[4] & 0x07; |
887 | 628 is16_9 = (vsc_pack && ((vsc_pack[2] & 0x07) == 0x02 || |
629 (!apt && (vsc_pack[2] & 0x07) == 0x07))); | |
995 | 630 avctx->sample_aspect_ratio = c->sys->sar[is16_9]; |
631 avctx->bit_rate = av_rescale(c->sys->frame_size * 8, | |
632 c->sys->frame_rate, | |
633 c->sys->frame_rate_base); | |
634 size = c->sys->frame_size; | |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
635 } |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
636 return size; |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
637 } |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
638 |
885 | 639 /* |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
640 * The following 6 functions constitute our interface to the world |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
641 */ |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
642 |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
643 int dv_assemble_frame(DVMuxContext *c, AVStream* st, |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
644 const uint8_t* data, int data_size, uint8_t** frame) |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
645 { |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
646 uint8_t pcm[8192]; |
995 | 647 int i; |
885 | 648 |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
649 *frame = &c->frame_buf[0]; |
995 | 650 if (c->has_audio && c->has_video && |
651 (c->has_audio == -1 || c->has_audio == c->n_ast)) { | |
652 /* must be a stale frame */ | |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
653 dv_format_frame(c, *frame); |
887 | 654 c->frames++; |
655 if (c->has_audio > 0) | |
656 c->has_audio = 0; | |
657 c->has_video = 0; | |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
658 } |
885 | 659 |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
764
diff
changeset
|
660 if (st->codec->codec_type == CODEC_TYPE_VIDEO) { |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
661 /* FIXME: we have to have more sensible approach than this one */ |
887 | 662 if (c->has_video) |
663 av_log(st->codec, AV_LOG_ERROR, "Can't process DV frame #%d. Insufficient audio data or severe sync problem.\n", c->frames); | |
885 | 664 |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
665 dv_inject_video(c, data, *frame); |
887 | 666 c->has_video = 1; |
667 data_size = 0; | |
668 if (c->has_audio < 0) | |
669 goto out; | |
885 | 670 } |
671 | |
995 | 672 for (i = 0; i < c->n_ast; i++) { |
673 int reqasize, fsize; | |
674 if (st != c->ast[i]) | |
675 continue; | |
676 reqasize = 4 * dv_audio_frame_size(c->sys, c->frames); | |
677 fsize = fifo_size(&c->audio_data[i], c->audio_data[i].rptr); | |
678 if (st->codec->codec_type == CODEC_TYPE_AUDIO || | |
679 (c->has_video && fsize >= reqasize)) { | |
680 if (fsize + data_size >= reqasize && (c->has_audio < c->n_ast)) { | |
681 if (fsize >= reqasize) { | |
682 fifo_read(&c->audio_data[i], &pcm[0], reqasize, &c->audio_data[i].rptr); | |
683 } else { | |
684 fifo_read(&c->audio_data[i], &pcm[0], fsize, &c->audio_data[i].rptr); | |
685 memcpy(&pcm[fsize], &data[0], reqasize - fsize); | |
686 data += reqasize - fsize; | |
687 data_size -= reqasize - fsize; | |
688 } | |
689 dv_inject_audio(c, &pcm[0], i, *frame); | |
690 c->has_audio += 1; | |
887 | 691 } |
995 | 692 /* FIXME: we have to have more sensible approach than this one */ |
693 if (fifo_size(&c->audio_data[i], c->audio_data[i].rptr) + data_size >= 100*AVCODEC_MAX_AUDIO_FRAME_SIZE) | |
694 av_log(st->codec, AV_LOG_ERROR, "Can't process DV frame #%d. Insufficient video data or severe sync problem.\n", c->frames); | |
1123
6992dd78ff68
Add (mostly) const to variable and parameter declaration, where a char* was
diego
parents:
1048
diff
changeset
|
695 fifo_write(&c->audio_data[i], data, data_size, &c->audio_data[i].wptr); |
887 | 696 } |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
697 } |
531
2af447b91329
* let DV muxer generate audioless DV streams. This might not be 100%
romansh
parents:
528
diff
changeset
|
698 out: |
995 | 699 return ((c->has_audio == -1 || c->has_audio == c->n_ast) && c->has_video) ? c->sys->frame_size : 0; |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
700 } |
0 | 701 |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
702 DVMuxContext* dv_init_mux(AVFormatContext* s) |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
703 { |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
704 DVMuxContext *c; |
531
2af447b91329
* let DV muxer generate audioless DV streams. This might not be 100%
romansh
parents:
528
diff
changeset
|
705 AVStream *vst = NULL; |
2af447b91329
* let DV muxer generate audioless DV streams. This might not be 100%
romansh
parents:
528
diff
changeset
|
706 int i; |
2af447b91329
* let DV muxer generate audioless DV streams. This might not be 100%
romansh
parents:
528
diff
changeset
|
707 |
995 | 708 /* we support at most 1 video and 2 audio streams */ |
709 if (s->nb_streams > 3) | |
531
2af447b91329
* let DV muxer generate audioless DV streams. This might not be 100%
romansh
parents:
528
diff
changeset
|
710 return NULL; |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
711 |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
712 c = av_mallocz(sizeof(DVMuxContext)); |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
713 if (!c) |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
714 return NULL; |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
715 |
995 | 716 c->n_ast = 0; |
717 c->ast[0] = c->ast[1] = NULL; | |
718 | |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
719 /* We have to sort out where audio and where video stream is */ |
531
2af447b91329
* let DV muxer generate audioless DV streams. This might not be 100%
romansh
parents:
528
diff
changeset
|
720 for (i=0; i<s->nb_streams; i++) { |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
764
diff
changeset
|
721 switch (s->streams[i]->codec->codec_type) { |
887 | 722 case CODEC_TYPE_VIDEO: |
723 vst = s->streams[i]; | |
724 break; | |
725 case CODEC_TYPE_AUDIO: | |
995 | 726 c->ast[c->n_ast++] = s->streams[i]; |
727 break; | |
887 | 728 default: |
729 goto bail_out; | |
730 } | |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
731 } |
885 | 732 |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
733 /* Some checks -- DV format is very picky about its incoming streams */ |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
764
diff
changeset
|
734 if (!vst || vst->codec->codec_id != CODEC_ID_DVVIDEO) |
531
2af447b91329
* let DV muxer generate audioless DV streams. This might not be 100%
romansh
parents:
528
diff
changeset
|
735 goto bail_out; |
995 | 736 for (i=0; i<c->n_ast; i++) { |
737 if (c->ast[i] && (c->ast[i]->codec->codec_id != CODEC_ID_PCM_S16LE || | |
738 c->ast[i]->codec->sample_rate != 48000 || | |
739 c->ast[i]->codec->channels != 2)) | |
740 goto bail_out; | |
741 } | |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
764
diff
changeset
|
742 c->sys = dv_codec_profile(vst->codec); |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
743 if (!c->sys) |
887 | 744 goto bail_out; |
885 | 745 |
995 | 746 if((c->n_ast > 1) && (c->sys->n_difchan < 2)) { |
747 /* only 1 stereo pair is allowed in 25Mbps mode */ | |
748 goto bail_out; | |
749 } | |
750 | |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
751 /* Ok, everything seems to be in working order */ |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
752 c->frames = 0; |
995 | 753 c->has_audio = c->n_ast ? 0 : -1; |
531
2af447b91329
* let DV muxer generate audioless DV streams. This might not be 100%
romansh
parents:
528
diff
changeset
|
754 c->has_video = 0; |
420
e440fb884442
* making it possible to specify recording date and time in a stream
romansh
parents:
417
diff
changeset
|
755 c->start_time = (time_t)s->timestamp; |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
756 c->aspect = 0; /* 4:3 is the default */ |
885 | 757 if ((int)(av_q2d(vst->codec->sample_aspect_ratio) * vst->codec->width / vst->codec->height * 10) == 17) /* 16:9 */ |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
758 c->aspect = 0x07; |
37 | 759 |
995 | 760 for (i=0; i<c->n_ast; i++) { |
761 if (c->ast[i] && fifo_init(&c->audio_data[i], 100*AVCODEC_MAX_AUDIO_FRAME_SIZE) < 0) { | |
762 while (i>0) { | |
763 i--; | |
764 fifo_free(&c->audio_data[i]); | |
765 } | |
766 goto bail_out; | |
767 } | |
768 } | |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
769 |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
770 dv_format_frame(c, &c->frame_buf[0]); |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
771 |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
772 return c; |
885 | 773 |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
774 bail_out: |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
775 av_free(c); |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
776 return NULL; |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
777 } |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
778 |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
779 void dv_delete_mux(DVMuxContext *c) |
885 | 780 { |
995 | 781 int i; |
782 for (i=0; i < c->n_ast; i++) | |
783 fifo_free(&c->audio_data[i]); | |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
784 } |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
785 |
296
252946de6d3f
* DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents:
288
diff
changeset
|
786 DVDemuxContext* dv_init_demux(AVFormatContext *s) |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
787 { |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
788 DVDemuxContext *c; |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
789 |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
790 c = av_mallocz(sizeof(DVDemuxContext)); |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
791 if (!c) |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
792 return NULL; |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
793 |
296
252946de6d3f
* DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents:
288
diff
changeset
|
794 c->vst = av_new_stream(s, 0); |
532
772247018ade
* experimental dynamic audio stream allocation for DV demuxer. This
romansh
parents:
531
diff
changeset
|
795 if (!c->vst) { |
885 | 796 av_free(c); |
532
772247018ade
* experimental dynamic audio stream allocation for DV demuxer. This
romansh
parents:
531
diff
changeset
|
797 return NULL; |
772247018ade
* experimental dynamic audio stream allocation for DV demuxer. This
romansh
parents:
531
diff
changeset
|
798 } |
462
b69898ffc92a
move time_base (pts_num/pts_den) from AVFormatContext -> AVStream
michael
parents:
460
diff
changeset
|
799 |
995 | 800 c->sys = NULL; |
296
252946de6d3f
* DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents:
288
diff
changeset
|
801 c->fctx = s; |
532
772247018ade
* experimental dynamic audio stream allocation for DV demuxer. This
romansh
parents:
531
diff
changeset
|
802 c->ast[0] = c->ast[1] = NULL; |
296
252946de6d3f
* DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents:
288
diff
changeset
|
803 c->ach = 0; |
392 | 804 c->frames = 0; |
805 c->abytes = 0; | |
562
bf3231dd1d7c
* static allocation for audio packets. This will make it a little bit
romansh
parents:
560
diff
changeset
|
806 |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
764
diff
changeset
|
807 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
|
808 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
|
809 c->vst->codec->bit_rate = 25000000; |
524
0b9dfb0cddc8
* misc. fixes and hacks to improve timing detection in raw DV
romansh
parents:
523
diff
changeset
|
810 c->vst->start_time = 0; |
885 | 811 |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
812 return c; |
0 | 813 } |
814 | |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
815 int dv_get_packet(DVDemuxContext *c, AVPacket *pkt) |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
816 { |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
817 int size = -1; |
296
252946de6d3f
* DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents:
288
diff
changeset
|
818 int i; |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
819 |
296
252946de6d3f
* DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents:
288
diff
changeset
|
820 for (i=0; i<c->ach; i++) { |
252946de6d3f
* DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents:
288
diff
changeset
|
821 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
|
822 *pkt = c->audio_pkt[i]; |
887 | 823 c->audio_pkt[i].size = 0; |
824 size = pkt->size; | |
825 break; | |
296
252946de6d3f
* DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents:
288
diff
changeset
|
826 } |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
827 } |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
828 |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
829 return size; |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
830 } |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
831 |
885 | 832 int dv_produce_packet(DVDemuxContext *c, AVPacket *pkt, |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
833 uint8_t* buf, int buf_size) |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
834 { |
296
252946de6d3f
* DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents:
288
diff
changeset
|
835 int size, i; |
885 | 836 |
1048 | 837 if (buf_size < DV_PROFILE_BYTES || |
838 !(c->sys = dv_frame_profile(buf)) || | |
839 buf_size < c->sys->frame_size) { | |
840 return -1; /* Broken frame, or not enough data */ | |
841 } | |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
842 |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
843 /* Queueing audio packet */ |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
844 /* 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
|
845 size = dv_extract_audio_info(c, buf); |
252946de6d3f
* DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents:
288
diff
changeset
|
846 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
|
847 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
|
848 c->audio_pkt[i].pts = c->abytes * 30000*8 / c->ast[i]->codec->bit_rate; |
296
252946de6d3f
* DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents:
288
diff
changeset
|
849 } |
995 | 850 dv_extract_audio(buf, c->audio_buf[0], c->audio_buf[1], c->sys); |
392 | 851 c->abytes += size; |
885 | 852 |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
853 /* 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
|
854 size = dv_extract_video_info(c, buf); |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
855 av_init_packet(pkt); |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
856 pkt->data = buf; |
885 | 857 pkt->size = size; |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
858 pkt->flags |= PKT_FLAG_KEY; |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
859 pkt->stream_index = c->vst->id; |
741 | 860 pkt->pts = c->frames; |
885 | 861 |
392 | 862 c->frames++; |
296
252946de6d3f
* DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents:
288
diff
changeset
|
863 |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
864 return size; |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
865 } |
885 | 866 |
559
f5f85a07fafe
flags, rounding and cliping fix by (Nathan Kurz <nate at verse dot com>)
michael
parents:
532
diff
changeset
|
867 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
|
868 int64_t timestamp, int flags) |
392 | 869 { |
523
d788959a01e2
* seek in raw DV patch by Nathan Kurz (nate at verse dot com)
romansh
parents:
515
diff
changeset
|
870 // 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
|
871 const DVprofile* sys = dv_codec_profile(c->vst->codec); |
741 | 872 int64_t offset; |
764
cdb845a57ae4
drop most url_fileno() calls (allows to use ByteIOContext directly in caller apps instead of URLProtocol)
aurel
parents:
743
diff
changeset
|
873 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
|
874 int64_t max_offset = ((size-1) / sys->frame_size) * sys->frame_size; |
392 | 875 |
741 | 876 offset = sys->frame_size * timestamp; |
885 | 877 |
559
f5f85a07fafe
flags, rounding and cliping fix by (Nathan Kurz <nate at verse dot com>)
michael
parents:
532
diff
changeset
|
878 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
|
879 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
|
880 |
d788959a01e2
* seek in raw DV patch by Nathan Kurz (nate at verse dot com)
romansh
parents:
515
diff
changeset
|
881 return offset; |
392 | 882 } |
883 | |
562
bf3231dd1d7c
* static allocation for audio packets. This will make it a little bit
romansh
parents:
560
diff
changeset
|
884 void dv_flush_audio_packets(DVDemuxContext *c) |
bf3231dd1d7c
* static allocation for audio packets. This will make it a little bit
romansh
parents:
560
diff
changeset
|
885 { |
bf3231dd1d7c
* static allocation for audio packets. This will make it a little bit
romansh
parents:
560
diff
changeset
|
886 c->audio_pkt[0].size = c->audio_pkt[1].size = 0; |
bf3231dd1d7c
* static allocation for audio packets. This will make it a little bit
romansh
parents:
560
diff
changeset
|
887 } |
bf3231dd1d7c
* static allocation for audio packets. This will make it a little bit
romansh
parents:
560
diff
changeset
|
888 |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
889 /************************************************************ |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
890 * 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
|
891 ************************************************************/ |
885 | 892 |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
893 typedef struct RawDVContext { |
296
252946de6d3f
* DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents:
288
diff
changeset
|
894 DVDemuxContext* dv_demux; |
995 | 895 uint8_t buf[DV_MAX_FRAME_SIZE]; |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
896 } RawDVContext; |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
897 |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
898 static int dv_read_header(AVFormatContext *s, |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
899 AVFormatParameters *ap) |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
900 { |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
901 RawDVContext *c = s->priv_data; |
995 | 902 |
296
252946de6d3f
* DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents:
288
diff
changeset
|
903 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
|
904 if (!c->dv_demux) |
0b9dfb0cddc8
* misc. fixes and hacks to improve timing detection in raw DV
romansh
parents:
523
diff
changeset
|
905 return -1; |
885 | 906 |
995 | 907 if (get_buffer(&s->pb, c->buf, DV_PROFILE_BYTES) <= 0 || |
908 url_fseek(&s->pb, -DV_PROFILE_BYTES, SEEK_CUR) < 0) | |
524
0b9dfb0cddc8
* misc. fixes and hacks to improve timing detection in raw DV
romansh
parents:
523
diff
changeset
|
909 return AVERROR_IO; |
0b9dfb0cddc8
* misc. fixes and hacks to improve timing detection in raw DV
romansh
parents:
523
diff
changeset
|
910 |
995 | 911 c->dv_demux->sys = dv_frame_profile(c->buf); |
912 s->bit_rate = av_rescale(c->dv_demux->sys->frame_size * 8, | |
913 c->dv_demux->sys->frame_rate, | |
914 c->dv_demux->sys->frame_rate_base); | |
885 | 915 |
524
0b9dfb0cddc8
* misc. fixes and hacks to improve timing detection in raw DV
romansh
parents:
523
diff
changeset
|
916 return 0; |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
917 } |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
918 |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
919 |
0 | 920 static int dv_read_packet(AVFormatContext *s, AVPacket *pkt) |
921 { | |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
922 int size; |
885 | 923 RawDVContext *c = s->priv_data; |
924 | |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
925 size = dv_get_packet(c->dv_demux, pkt); |
885 | 926 |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
927 if (size < 0) { |
995 | 928 size = c->dv_demux->sys->frame_size; |
929 if (get_buffer(&s->pb, c->buf, size) <= 0) | |
887 | 930 return AVERROR_IO; |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
931 |
887 | 932 size = dv_produce_packet(c->dv_demux, pkt, c->buf, size); |
885 | 933 } |
934 | |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
935 return size; |
0 | 936 } |
937 | |
885 | 938 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
|
939 int64_t timestamp, int flags) |
392 | 940 { |
559
f5f85a07fafe
flags, rounding and cliping fix by (Nathan Kurz <nate at verse dot com>)
michael
parents:
532
diff
changeset
|
941 RawDVContext *r = s->priv_data; |
f5f85a07fafe
flags, rounding and cliping fix by (Nathan Kurz <nate at verse dot com>)
michael
parents:
532
diff
changeset
|
942 DVDemuxContext *c = r->dv_demux; |
f5f85a07fafe
flags, rounding and cliping fix by (Nathan Kurz <nate at verse dot com>)
michael
parents:
532
diff
changeset
|
943 int64_t offset= dv_frame_offset(s, c, timestamp, flags); |
392 | 944 |
995 | 945 c->frames= offset / c->sys->frame_size; |
562
bf3231dd1d7c
* static allocation for audio packets. This will make it a little bit
romansh
parents:
560
diff
changeset
|
946 if (c->ach) |
bf3231dd1d7c
* static allocation for audio packets. This will make it a little bit
romansh
parents:
560
diff
changeset
|
947 c->abytes= av_rescale(c->frames, |
995 | 948 c->ast[0]->codec->bit_rate * (int64_t)c->sys->frame_rate_base, |
949 8*c->sys->frame_rate); | |
885 | 950 |
562
bf3231dd1d7c
* static allocation for audio packets. This will make it a little bit
romansh
parents:
560
diff
changeset
|
951 dv_flush_audio_packets(c); |
559
f5f85a07fafe
flags, rounding and cliping fix by (Nathan Kurz <nate at verse dot com>)
michael
parents:
532
diff
changeset
|
952 return url_fseek(&s->pb, offset, SEEK_SET); |
392 | 953 } |
954 | |
0 | 955 static int dv_read_close(AVFormatContext *s) |
956 { | |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
957 RawDVContext *c = s->priv_data; |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
958 av_free(c->dv_demux); |
0 | 959 return 0; |
960 } | |
961 | |
903
68bc3ca12e79
Put muxer-specific code parts in #ifdef CONFIG_MUXERS.
diego
parents:
896
diff
changeset
|
962 #ifdef CONFIG_MUXERS |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
963 static int dv_write_header(AVFormatContext *s) |
203
184d22d04c84
* Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
119
diff
changeset
|
964 { |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
965 s->priv_data = dv_init_mux(s); |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
966 if (!s->priv_data) { |
370
845f9de2c883
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
363
diff
changeset
|
967 av_log(s, AV_LOG_ERROR, "Can't initialize DV format!\n" |
887 | 968 "Make sure that you supply exactly two streams:\n" |
995 | 969 " video: 25fps or 29.97fps, audio: 2ch/48Khz/PCM\n" |
970 " (50Mbps allows an optional second audio stream)\n"); | |
887 | 971 return -1; |
203
184d22d04c84
* Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
119
diff
changeset
|
972 } |
184d22d04c84
* Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
119
diff
changeset
|
973 return 0; |
184d22d04c84
* Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
119
diff
changeset
|
974 } |
184d22d04c84
* Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
119
diff
changeset
|
975 |
468 | 976 static int dv_write_packet(struct AVFormatContext *s, AVPacket *pkt) |
203
184d22d04c84
* Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
119
diff
changeset
|
977 { |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
978 uint8_t* frame; |
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
979 int fsize; |
885 | 980 |
468 | 981 fsize = dv_assemble_frame((DVMuxContext *)s->priv_data, s->streams[pkt->stream_index], |
982 pkt->data, pkt->size, &frame); | |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
983 if (fsize > 0) { |
885 | 984 put_buffer(&s->pb, frame, fsize); |
203
184d22d04c84
* Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
119
diff
changeset
|
985 put_flush_packet(&s->pb); |
885 | 986 } |
363
efd9dfe4f504
* turns out write_packet is supposed to return 0 on success, not
romansh
parents:
296
diff
changeset
|
987 return 0; |
203
184d22d04c84
* Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
119
diff
changeset
|
988 } |
184d22d04c84
* Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
119
diff
changeset
|
989 |
885 | 990 /* |
203
184d22d04c84
* Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
119
diff
changeset
|
991 * We might end up with some extra A/V data without matching counterpart. |
184d22d04c84
* Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
119
diff
changeset
|
992 * E.g. video data without enough audio to write the complete frame. |
885 | 993 * Currently we simply drop the last frame. I don't know whether this |
203
184d22d04c84
* Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
119
diff
changeset
|
994 * is the best strategy of all |
184d22d04c84
* Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
119
diff
changeset
|
995 */ |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
996 static int dv_write_trailer(struct AVFormatContext *s) |
203
184d22d04c84
* Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
119
diff
changeset
|
997 { |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
998 dv_delete_mux((DVMuxContext *)s->priv_data); |
203
184d22d04c84
* Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
119
diff
changeset
|
999 return 0; |
184d22d04c84
* Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
119
diff
changeset
|
1000 } |
903
68bc3ca12e79
Put muxer-specific code parts in #ifdef CONFIG_MUXERS.
diego
parents:
896
diff
changeset
|
1001 #endif /* CONFIG_MUXERS */ |
203
184d22d04c84
* Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
119
diff
changeset
|
1002 |
1169 | 1003 #ifdef CONFIG_DV_DEMUXER |
1004 AVInputFormat dv_demuxer = { | |
0 | 1005 "dv", |
1006 "DV video format", | |
262
f174d9c00bce
* DV handling was streamlined for both muxing/demuxing and
romansh
parents:
241
diff
changeset
|
1007 sizeof(RawDVContext), |
0 | 1008 NULL, |
1009 dv_read_header, | |
1010 dv_read_packet, | |
1011 dv_read_close, | |
392 | 1012 dv_read_seek, |
393 | 1013 .extensions = "dv,dif", |
0 | 1014 }; |
1169 | 1015 #endif |
1016 #ifdef CONFIG_DV_MUXER | |
1017 AVOutputFormat dv_muxer = { | |
0 | 1018 "dv", |
1019 "DV video format", | |
1020 NULL, | |
1021 "dv", | |
203
184d22d04c84
* Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
119
diff
changeset
|
1022 sizeof(DVMuxContext), |
184d22d04c84
* Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
119
diff
changeset
|
1023 CODEC_ID_PCM_S16LE, |
0 | 1024 CODEC_ID_DVVIDEO, |
1025 dv_write_header, | |
1026 dv_write_packet, | |
1027 dv_write_trailer, | |
1028 }; | |
903
68bc3ca12e79
Put muxer-specific code parts in #ifdef CONFIG_MUXERS.
diego
parents:
896
diff
changeset
|
1029 #endif |