annotate dv.c @ 896:edbe5c3717f9 libavformat

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