annotate dv.c @ 339:a07c42730632 libavformat

forgot ...
author michael
date Sat, 03 Jan 2004 13:29:46 +0000
parents 252946de6d3f
children efd9dfe4f504
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1 /*
262
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
2 * General DV muxer/demuxer
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
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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;
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
33 AVStream* ast[2];
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
34 AVPacket audio_pkt[2];
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
35 int ach;
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
36 };
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
37
296
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
38 struct DVMuxContext {
262
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
39 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
40 uint8_t frame_buf[144000]; /* frame under contruction */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
41 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
42 int frames; /* Number of a current frame */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
43 time_t start_time; /* Start time of recording */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
44 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
45 int has_audio; /* frame under contruction has audio */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
46 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
47 };
262
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
48
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
49 enum dv_section_type {
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
50 dv_sect_header = 0x1f,
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
51 dv_sect_subcode = 0x3f,
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
52 dv_sect_vaux = 0x56,
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
53 dv_sect_audio = 0x76,
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
54 dv_sect_video = 0x96,
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
55 };
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
56
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
57 enum dv_pack_type {
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
58 dv_header525 = 0x3f, /* see dv_write_pack for important details on */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
59 dv_header625 = 0xbf, /* these two packs */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
60 dv_timecode = 0x13,
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
61 dv_audio_source = 0x50,
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
62 dv_audio_control = 0x51,
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
63 dv_audio_recdate = 0x52,
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
64 dv_audio_rectime = 0x53,
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
65 dv_video_source = 0x60,
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
66 dv_video_control = 0x61,
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
67 dv_viedo_recdate = 0x62,
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
68 dv_video_rectime = 0x63,
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
69 dv_unknown_pack = 0xff,
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
70 };
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
71
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
72
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
73
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 * The reason why the following three big ugly looking tables are
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
76 * here is my lack of DV spec IEC 61834. The tables were basically
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
77 * constructed to make code that places packs in SSYB, VAUX and
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
78 * 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
79 * 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
80 * 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
81 * 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
82 * 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
83 * accommodate all the quirks. Later on, if possible, some of them
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
84 * will be folded into smaller tables and/or switch-if logic. For
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
85 * 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
86 */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
87
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
88 static const int dv_ssyb_packs_dist[12][6] = {
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
89 { 0x13, 0x13, 0x13, 0x13, 0x13, 0x13 },
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
90 { 0x13, 0x13, 0x13, 0x13, 0x13, 0x13 },
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
91 { 0x13, 0x13, 0x13, 0x13, 0x13, 0x13 },
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, 0x62, 0x63, 0x13, 0x62, 0x63 },
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
96 { 0x13, 0x62, 0x63, 0x13, 0x62, 0x63 },
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
97 { 0x13, 0x62, 0x63, 0x13, 0x62, 0x63 },
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 };
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
102
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
103 static const int dv_vaux_packs_dist[12][15] = {
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
104 { 0x60, 0x61, 0x62, 0x63, 0xff, 0xff, 0xff, 0xff, 0xff,
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
105 0x60, 0x61, 0x62, 0x63, 0xff, 0xff },
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
106 { 0x60, 0x61, 0x62, 0x63, 0xff, 0xff, 0xff, 0xff, 0xff,
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
107 0x60, 0x61, 0x62, 0x63, 0xff, 0xff },
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
108 { 0x60, 0x61, 0x62, 0x63, 0xff, 0xff, 0xff, 0xff, 0xff,
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
109 0x60, 0x61, 0x62, 0x63, 0xff, 0xff },
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
110 { 0x60, 0x61, 0x62, 0x63, 0xff, 0xff, 0xff, 0xff, 0xff,
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
111 0x60, 0x61, 0x62, 0x63, 0xff, 0xff },
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
112 { 0x60, 0x61, 0x62, 0x63, 0xff, 0xff, 0xff, 0xff, 0xff,
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
113 0x60, 0x61, 0x62, 0x63, 0xff, 0xff },
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
114 { 0x60, 0x61, 0x62, 0x63, 0xff, 0xff, 0xff, 0xff, 0xff,
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
115 0x60, 0x61, 0x62, 0x63, 0xff, 0xff },
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
116 { 0x60, 0x61, 0x62, 0x63, 0xff, 0xff, 0xff, 0xff, 0xff,
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
117 0x60, 0x61, 0x62, 0x63, 0xff, 0xff },
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
118 { 0x60, 0x61, 0x62, 0x63, 0xff, 0xff, 0xff, 0xff, 0xff,
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
119 0x60, 0x61, 0x62, 0x63, 0xff, 0xff },
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
120 { 0x60, 0x61, 0x62, 0x63, 0xff, 0xff, 0xff, 0xff, 0xff,
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
121 0x60, 0x61, 0x62, 0x63, 0xff, 0xff },
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
122 { 0x60, 0x61, 0x62, 0x63, 0xff, 0xff, 0xff, 0xff, 0xff,
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
123 0x60, 0x61, 0x62, 0x63, 0xff, 0xff },
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
124 { 0x60, 0x61, 0x62, 0x63, 0xff, 0xff, 0xff, 0xff, 0xff,
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
125 0x60, 0x61, 0x62, 0x63, 0xff, 0xff },
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
126 { 0x60, 0x61, 0x62, 0x63, 0xff, 0xff, 0xff, 0xff, 0xff,
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
127 0x60, 0x61, 0x62, 0x63, 0xff, 0xff },
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
128 };
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
129
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
130 static const int dv_aaux_packs_dist[12][9] = {
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
131 { 0xff, 0xff, 0xff, 0x50, 0x51, 0x52, 0x53, 0xff, 0xff },
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
132 { 0x50, 0x51, 0x52, 0x53, 0xff, 0xff, 0xff, 0xff, 0xff },
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
133 { 0xff, 0xff, 0xff, 0x50, 0x51, 0x52, 0x53, 0xff, 0xff },
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
134 { 0x50, 0x51, 0x52, 0x53, 0xff, 0xff, 0xff, 0xff, 0xff },
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
135 { 0xff, 0xff, 0xff, 0x50, 0x51, 0x52, 0x53, 0xff, 0xff },
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
136 { 0x50, 0x51, 0x52, 0x53, 0xff, 0xff, 0xff, 0xff, 0xff },
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
137 { 0xff, 0xff, 0xff, 0x50, 0x51, 0x52, 0x53, 0xff, 0xff },
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
138 { 0x50, 0x51, 0x52, 0x53, 0xff, 0xff, 0xff, 0xff, 0xff },
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
139 { 0xff, 0xff, 0xff, 0x50, 0x51, 0x52, 0x53, 0xff, 0xff },
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
140 { 0x50, 0x51, 0x52, 0x53, 0xff, 0xff, 0xff, 0xff, 0xff },
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
141 { 0xff, 0xff, 0xff, 0x50, 0x51, 0x52, 0x53, 0xff, 0xff },
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
142 { 0x50, 0x51, 0x52, 0x53, 0xff, 0xff, 0xff, 0xff, 0xff },
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
143 };
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
144
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
145 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
146 {
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
147 uint16_t shift, result;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
148
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
149 sample = (sample < 0x800) ? sample : sample | 0xf000;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
150 shift = (sample & 0xf00) >> 8;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
151
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
152 if (shift < 0x2 || shift > 0xd) {
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
153 result = sample;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
154 } else if (shift < 0x8) {
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
155 shift--;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
156 result = (sample - (256 * shift)) << shift;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
157 } else {
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
158 shift = 0xe - shift;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
159 result = ((sample + ((256 * shift) + 1)) << shift) - 1;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
160 }
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
161
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
162 return result;
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 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
166 {
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
167 return sys->audio_samples_dist[frame % (sizeof(sys->audio_samples_dist)/
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
168 sizeof(sys->audio_samples_dist[0]))];
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
169 }
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
170
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
171 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
172 {
262
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
173 struct tm tc;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
174 time_t ct;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
175 int ltc_frame;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
176
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
177 buf[0] = (uint8_t)pack_id;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
178 switch (pack_id) {
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
179 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
180 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
181 buf[1] = 0xf8 | /* reserved -- always 1 */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
182 (0 & 0x07); /* APT: Track application ID */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
183 buf[2] = (0 << 7) | /* TF1: audio data is 0 - valid; 1 - invalid */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
184 (0x0f << 3) | /* reserved -- always 1 */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
185 (0 & 0x07); /* AP1: Audio application ID */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
186 buf[3] = (0 << 7) | /* TF2: video data is 0 - valid; 1 - invalid */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
187 (0x0f << 3) | /* reserved -- always 1 */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
188 (0 & 0x07); /* AP2: Video application ID */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
189 buf[4] = (0 << 7) | /* TF3: subcode(SSYB) is 0 - valid; 1 - invalid */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
190 (0x0f << 3) | /* reserved -- always 1 */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
191 (0 & 0x07); /* AP3: Subcode application ID */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
192 break;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
193 case dv_timecode:
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
194 ct = (time_t)(c->frames / ((float)c->sys->frame_rate /
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
195 (float)c->sys->frame_rate_base));
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
196 localtime_r(&ct, &tc);
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
197 /*
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
198 * LTC drop-frame frame counter drops two frames (0 and 1) every
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
199 * minute, unless it is exactly divisible by 10
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
200 */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
201 ltc_frame = (c->frames + 2*ct/60 - 2*ct/600) % c->sys->ltc_divisor;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
202 buf[1] = (0 << 7) | /* Color fame: 0 - unsync; 1 - sync mode */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
203 (1 << 6) | /* Drop frame timecode: 0 - nondrop; 1 - drop */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
204 ((ltc_frame / 10) << 4) | /* Tens of frames */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
205 (ltc_frame % 10); /* Units of frames */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
206 buf[2] = (1 << 7) | /* Biphase mark polarity correction: 0 - even; 1 - odd */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
207 ((tc.tm_sec / 10) << 4) | /* Tens of seconds */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
208 (tc.tm_sec % 10); /* Units of seconds */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
209 buf[3] = (1 << 7) | /* Binary group flag BGF0 */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
210 ((tc.tm_min / 10) << 4) | /* Tens of minutes */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
211 (tc.tm_min % 10); /* Units of minutes */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
212 buf[4] = (1 << 7) | /* Binary group flag BGF2 */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
213 (1 << 6) | /* Binary group flag BGF1 */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
214 ((tc.tm_hour / 10) << 4) | /* Tens of hours */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
215 (tc.tm_hour % 10); /* Units of hours */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
216 break;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
217 case dv_audio_source: /* AAUX source pack */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
218 buf[1] = (0 << 7) | /* locked mode */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
219 (1 << 6) | /* reserved -- always 1 */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
220 (dv_audio_frame_size(c->sys, c->frames) -
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
221 c->sys->audio_min_samples[0]);
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
222 /* # of samples */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
223 buf[2] = (0 << 7) | /* multi-stereo */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
224 (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
225 (0 << 4) | /* pair bit: 0 -- one pair of channels */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
226 0; /* audio mode */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
227 buf[3] = (1 << 7) | /* res */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
228 (1 << 6) | /* multi-language flag */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
229 (c->sys->dsf << 5) | /* system: 60fields/50fields */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
230 0; /* definition: 0 -- SD (525/625) */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
231 buf[4] = (1 << 7) | /* emphasis: 1 -- off */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
232 (0 << 6) | /* emphasis time constant: 0 -- reserved */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
233 (0 << 3) | /* frequency: 0 -- 48Khz, 1 -- 44,1Khz, 2 -- 32Khz */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
234 0; /* quantization: 0 -- 16bit linear, 1 -- 12bit nonlinear */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
235 break;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
236 case dv_audio_control:
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
237 buf[1] = (0 << 6) | /* copy protection: 0 -- unrestricted */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
238 (1 << 4) | /* input source: 1 -- digital input */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
239 (3 << 2) | /* compression: 3 -- no information */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
240 0; /* misc. info/SMPTE emphasis off */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
241 buf[2] = (1 << 7) | /* recording start point: 1 -- no */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
242 (1 << 6) | /* recording end point: 1 -- no */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
243 (1 << 3) | /* recording mode: 1 -- original */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
244 7;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
245 buf[3] = (1 << 7) | /* direction: 1 -- forward */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
246 0x20; /* speed */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
247 buf[4] = (1 << 7) | /* reserved -- always 1 */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
248 0x7f; /* genre category */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
249 break;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
250 case dv_audio_recdate:
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
251 case dv_viedo_recdate: /* VAUX recording date */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
252 ct = c->start_time + (time_t)(c->frames /
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
253 ((float)c->sys->frame_rate / (float)c->sys->frame_rate_base));
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
254 localtime_r(&ct, &tc);
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
255 buf[1] = 0xff; /* ds, tm, tens of time zone, units of time zone */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
256 /* 0xff is very likely to be "unknown" */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
257 buf[2] = (3 << 6) | /* reserved -- always 1 */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
258 ((tc.tm_mday / 10) << 4) | /* Tens of day */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
259 (tc.tm_mday % 10); /* Units of day */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
260 buf[3] = /* we set high 4 bits to 0, shouldn't we set them to week? */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
261 (tc.tm_mon % 10); /* Units of month */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
262 buf[4] = (((tc.tm_year % 100) / 10) << 4) | /* Tens of year */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
263 (tc.tm_year % 10); /* Units of year */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
264 break;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
265 case dv_audio_rectime: /* AAUX recording time */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
266 case dv_video_rectime: /* VAUX recording time */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
267 ct = c->start_time + (time_t)(c->frames /
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
268 ((float)c->sys->frame_rate / (float)c->sys->frame_rate_base));
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
269 localtime_r(&ct, &tc);
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
270 buf[1] = (3 << 6) | /* reserved -- always 1 */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
271 0x3f; /* tens of frame, units of frame: 0x3f - "unknown" ? */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
272 buf[2] = (1 << 7) | /* reserved -- always 1 */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
273 ((tc.tm_sec / 10) << 4) | /* Tens of seconds */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
274 (tc.tm_sec % 10); /* Units of seconds */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
275 buf[3] = (1 << 7) | /* reserved -- always 1 */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
276 ((tc.tm_min / 10) << 4) | /* Tens of minutes */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
277 (tc.tm_min % 10); /* Units of minutes */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
278 buf[4] = (3 << 6) | /* reserved -- always 1 */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
279 ((tc.tm_hour / 10) << 4) | /* Tens of hours */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
280 (tc.tm_hour % 10); /* Units of hours */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
281 break;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
282 case dv_video_source:
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
283 buf[1] = 0xff; /* reserved -- always 1 */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
284 buf[2] = (1 << 7) | /* B/W: 0 - b/w, 1 - color */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
285 (1 << 6) | /* following CLF is valid - 0, invalid - 1 */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
286 (3 << 4) | /* CLF: color frames id (see ITU-R BT.470-4) */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
287 0xf; /* reserved -- always 1 */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
288 buf[3] = (3 << 6) | /* reserved -- always 1 */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
289 (c->sys->dsf << 5) | /* system: 60fields/50fields */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
290 0; /* signal type video compression */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
291 buf[4] = 0xff; /* VISC: 0xff -- no information */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
292 break;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
293 case dv_video_control:
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
294 buf[1] = (0 << 6) | /* Copy generation management (CGMS) 0 -- free */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
295 0x3f; /* reserved -- always 1 */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
296 buf[2] = 0xc8 | /* reserved -- always b11001xxx */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
297 c->aspect;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
298 buf[3] = (1 << 7) | /* Frame/field flag 1 -- frame, 0 -- field */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
299 (1 << 6) | /* First/second field flag 0 -- field 2, 1 -- field 1 */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
300 (1 << 5) | /* Frame change flag 0 -- same picture as before, 1 -- different */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
301 (1 << 4) | /* 1 - interlaced, 0 - noninterlaced */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
302 0xc; /* reserved -- always b1100 */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
303 buf[4] = 0xff; /* reserved -- always 1 */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
304 break;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
305 default:
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
306 buf[1] = buf[2] = buf[3] = buf[4] = 0xff;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
307 }
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
308 return 5;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
309 }
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
310
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
311 static inline int dv_write_dif_id(enum dv_section_type t, uint8_t seq_num,
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
312 uint8_t dif_num, uint8_t* buf)
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 buf[0] = (uint8_t)t; /* Section type */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
315 buf[1] = (seq_num<<4) | /* DIF seq number 0-9 for 525/60; 0-11 for 625/50 */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
316 (0 << 3) | /* FSC: for 50Mb/s 0 - first channel; 1 - second */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
317 7; /* reserved -- always 1 */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
318 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
319 return 3;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
320 }
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
321
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
322 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
323 {
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
324 if (syb_num == 0 || syb_num == 6) {
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
325 buf[0] = (fr<<7) | /* FR ID 1 - first half of each channel; 0 - second */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
326 (0<<4) | /* AP3 (Subcode application ID) */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
327 0x0f; /* reserved -- always 1 */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
328 }
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
329 else if (syb_num == 11) {
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
330 buf[0] = (fr<<7) | /* FR ID 1 - first half of each channel; 0 - second */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
331 0x7f; /* reserved -- always 1 */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
332 }
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
333 else {
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
334 buf[0] = (fr<<7) | /* FR ID 1 - first half of each channel; 0 - second */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
335 (0<<4) | /* APT (Track application ID) */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
336 0x0f; /* reserved -- always 1 */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
337 }
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
338 buf[1] = 0xf0 | /* reserved -- always 1 */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
339 (syb_num & 0x0f); /* SSYB number 0 - 11 */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
340 buf[2] = 0xff; /* reserved -- always 1 */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
341 return 3;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
342 }
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
343
262
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
344 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
345 {
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
346 int i, j, k;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
347
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
348 for (i = 0; i < c->sys->difseg_size; i++) {
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
349 memset(buf, 0xff, 80 * 6); /* First 6 DIF blocks are for control data */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
350
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
351 /* DV header: 1DIF */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
352 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
353 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
354 buf += 72; /* unused bytes */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
355
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
356 /* DV subcode: 2DIFs */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
357 for (j = 0; j < 2; j++) {
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
358 buf += dv_write_dif_id( dv_sect_subcode, i, j, buf);
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
359 for (k = 0; k < 6; k++) {
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
360 buf += dv_write_ssyb_id(k, (i < c->sys->difseg_size/2), buf);
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
361 buf += dv_write_pack(dv_ssyb_packs_dist[i][k], c, buf);
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
362 }
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
363 buf += 29; /* unused bytes */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
364 }
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
365
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
366 /* DV VAUX: 3DIFs */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
367 for (j = 0; j < 3; j++) {
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
368 buf += dv_write_dif_id(dv_sect_vaux, i, j, buf);
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
369 for (k = 0; k < 15 ; k++)
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
370 buf += dv_write_pack(dv_vaux_packs_dist[i][k], c, buf);
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
371 buf += 2; /* unused bytes */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
372 }
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
373
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
374 /* DV Audio/Video: 135 Video DIFs + 9 Audio DIFs */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
375 for (j = 0; j < 135; j++) {
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
376 if (j%15 == 0) {
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
377 buf += dv_write_dif_id(dv_sect_audio, i, j/15, buf);
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
378 buf += dv_write_pack(dv_aaux_packs_dist[i][j/15], c, buf);
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
379 buf += 72; /* shuffled PCM audio */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
380 }
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
381 buf += dv_write_dif_id(dv_sect_video, i, j, buf);
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
382 buf += 77; /* 1 video macro block: 1 bytes control
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
383 4 * 14 bytes Y 8x8 data
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
384 10 bytes Cr 8x8 data
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
385 10 bytes Cb 8x8 data */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
386 }
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
387 }
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
388 }
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
389
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
390 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
391 {
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
392 int i, j, d, of;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
393 for (i = 0; i < c->sys->difseg_size; i++) {
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
394 frame_ptr += 6 * 80; /* skip DIF segment header */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
395 for (j = 0; j < 9; j++) {
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
396 for (d = 8; d < 80; d+=2) {
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
397 of = c->sys->audio_shuffle[i][j] + (d - 8)/2 * c->sys->audio_stride;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
398 frame_ptr[d] = pcm[of*2+1]; // FIXME: may be we have to admit
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
399 frame_ptr[d+1] = pcm[of*2]; // that DV is a big endian PCM
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
400 }
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
401 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
402 }
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
403 }
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
404 }
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
405
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
406 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
407 {
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
408 int i, j;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
409 int ptr = 0;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
410
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
411 for (i = 0; i < c->sys->difseg_size; i++) {
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
412 ptr += 6 * 80; /* skip DIF segment header */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
413 for (j = 0; j < 135; j++) {
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
414 if (j%15 == 0)
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
415 ptr += 80; /* skip Audio DIF */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
416 ptr += 3;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
417 memcpy(frame_ptr + ptr, video_data + ptr, 77);
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
418 ptr += 77;
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 }
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
421 }
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
422
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
423 /*
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
424 * 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
425 * 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
426 * 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
427 */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
428 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
429 {
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
430 int offs;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
431
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
432 switch (t) {
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
433 case dv_audio_source:
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
434 offs = (80*6 + 80*16*3 + 3);
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
435 break;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
436 case dv_audio_control:
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
437 offs = (80*6 + 80*16*4 + 3);
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
438 break;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
439 case dv_video_control:
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
440 offs = (80*5 + 48 + 5);
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
441 break;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
442 default:
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
443 return NULL;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
444 }
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
445
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
446 return (frame[offs] == t ? &frame[offs] : NULL);
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
447 }
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
448
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
449 /*
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
450 * There's a couple of assumptions being made here:
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
451 * 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
452 * 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
453 * 2. We don't do software emphasis.
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
454 * 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
455 * are converted into 16bit linear ones.
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
456 */
296
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
457 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
458 {
296
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
459 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
460 uint16_t lc, rc;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
461 const DVprofile* sys;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
462 const uint8_t* as_pack;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
463
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
464 as_pack = dv_extract_pack(frame, dv_audio_source);
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
465 if (!as_pack) /* No audio ? */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
466 return 0;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
467
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
468 sys = dv_frame_profile(frame);
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
469 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
470 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
471 quant = as_pack[4] & 0x07; /* 0 - 16bit linear, 1 - 12bit nonlinear */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
472
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
473 if (quant > 1)
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
474 return -1; /* Unsupported quantization */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
475
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
476 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
477 half_ch = sys->difseg_size/2;
262
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
478
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
479 /* for each DIF segment */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
480 for (i = 0; i < sys->difseg_size; i++) {
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
481 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
482 if (quant == 1 && i == half_ch) {
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
483 if (!pcm2)
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
484 break;
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
485 else
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
486 pcm = pcm2;
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
487 }
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
488
262
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
489 for (j = 0; j < 9; j++) {
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
490 for (d = 8; d < 80; d += 2) {
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
491 if (quant == 0) { /* 16bit quantization */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
492 of = sys->audio_shuffle[i][j] + (d - 8)/2 * sys->audio_stride;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
493 if (of*2 >= size)
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
494 continue;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
495
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
496 pcm[of*2] = frame[d+1]; // FIXME: may be we have to admit
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
497 pcm[of*2+1] = frame[d]; // that DV is a big endian PCM
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
498 if (pcm[of*2+1] == 0x80 && pcm[of*2] == 0x00)
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
499 pcm[of*2+1] = 0;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
500 } else { /* 12bit quantization */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
501 lc = ((uint16_t)frame[d] << 4) |
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
502 ((uint16_t)frame[d+2] >> 4);
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
503 rc = ((uint16_t)frame[d+1] << 4) |
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
504 ((uint16_t)frame[d+2] & 0x0f);
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
505 lc = (lc == 0x800 ? 0 : dv_audio_12to16(lc));
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
506 rc = (rc == 0x800 ? 0 : dv_audio_12to16(rc));
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
507
296
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
508 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
509 if (of*2 >= size)
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
510 continue;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
511
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
512 pcm[of*2] = lc & 0xff; // FIXME: may be we have to admit
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
513 pcm[of*2+1] = lc >> 8; // that DV is a big endian PCM
296
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
514 of = sys->audio_shuffle[i%half_ch+half_ch][j] +
262
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
515 (d - 8)/3 * sys->audio_stride;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
516 pcm[of*2] = rc & 0xff; // FIXME: may be we have to admit
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
517 pcm[of*2+1] = rc >> 8; // that DV is a big endian PCM
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
518 ++d;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
519 }
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
520 }
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
521
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
522 frame += 16 * 80; /* 15 Video DIFs + 1 Audio DIF */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
523 }
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
524 }
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
525
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
526 return size;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
527 }
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
528
296
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
529 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
530 {
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
531 const uint8_t* as_pack;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
532 const DVprofile* sys;
296
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
533 int freq, smpls, quant, i;
37
8f76666c71c2 DV audio decoder by Roman Shaposhnick
bellard
parents: 28
diff changeset
534
262
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
535 sys = dv_frame_profile(frame);
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
536 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
537 if (!as_pack || !sys) { /* No audio ? */
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
538 c->ach = 0;
262
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
539 return -1;
296
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
540 }
262
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
541
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
542 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
543 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
544 quant = as_pack[4] & 0x07; /* 0 - 16bit linear, 1 - 12bit nonlinear */
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
545 c->ach = (quant && freq == 2) ? 2 : 1;
262
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
546
296
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
547 /* The second stereo channel could appear in IEC 61834 stream only */
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
548 if (c->ach == 2 && !c->ast[1]) {
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
549 c->ast[1] = av_new_stream(c->fctx, 0);
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
550 if (c->ast[1]) {
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
551 c->ast[1]->codec.codec_type = CODEC_TYPE_AUDIO;
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
552 c->ast[1]->codec.codec_id = CODEC_ID_PCM_S16LE;
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
553 } else
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
554 c->ach = 1;
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
555 }
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
556 for (i=0; i<c->ach; i++) {
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
557 c->ast[i]->codec.sample_rate = dv_audio_frequency[freq];
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
558 c->ast[i]->codec.channels = 2;
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
559 c->ast[i]->codec.bit_rate = 2 * dv_audio_frequency[freq] * 16;
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
560 }
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
561
262
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
562 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
563 }
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
564
296
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
565 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
566 {
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
567 const DVprofile* sys;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
568 const uint8_t* vsc_pack;
296
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
569 AVCodecContext* avctx;
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
570 int apt, is16_9;
262
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
571 int size = 0;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
572
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
573 sys = dv_frame_profile(frame);
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
574 if (sys) {
296
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
575 avctx = &c->vst->codec;
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
576
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
577 avctx->frame_rate = sys->frame_rate;
262
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
578 avctx->frame_rate_base = sys->frame_rate_base;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
579 avctx->width = sys->width;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
580 avctx->height = sys->height;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
581 avctx->pix_fmt = sys->pix_fmt;
296
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
582
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
583 vsc_pack = dv_extract_pack(frame, dv_video_control);
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
584 apt = frame[4] & 0x07;
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
585 is16_9 = (vsc_pack && (vsc_pack[2] & 0x07) == (apt?0x02:0x07));
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
586 avctx->sample_aspect_ratio = sys->sar[is16_9];
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
587
262
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
588 size = sys->frame_size;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
589 }
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
590 return size;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
591 }
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
592
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
593 /*
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
594 * 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
595 */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
596
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
597 int dv_assemble_frame(DVMuxContext *c, AVStream* st,
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
598 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
599 {
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
600 uint8_t pcm[8192];
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
601 int fsize, reqasize;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
602
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
603 *frame = &c->frame_buf[0];
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
604 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
605 dv_format_frame(c, *frame);
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
606 c->frames++;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
607 c->has_audio = c->has_video = 0;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
608 }
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
609
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
610 if (st->codec.codec_type == CODEC_TYPE_VIDEO) {
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
611 /* 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
612 if (c->has_video)
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
613 fprintf(stderr, "Can't process DV frame #%d. Insufficient audio data or severe sync problem.\n", c->frames);
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
614
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
615 dv_inject_video(c, data, *frame);
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
616 c->has_video = 1;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
617 data_size = 0;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
618 }
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
619
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
620 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
621 fsize = fifo_size(&c->audio_data, c->audio_data.rptr);
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
622 if (st->codec.codec_type == CODEC_TYPE_AUDIO || (c->has_video && fsize >= reqasize)) {
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
623 if (fsize + data_size >= reqasize && !c->has_audio) {
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
624 if (fsize >= reqasize) {
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
625 fifo_read(&c->audio_data, &pcm[0], reqasize, &c->audio_data.rptr);
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
626 } else {
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
627 fifo_read(&c->audio_data, &pcm[0], fsize, &c->audio_data.rptr);
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
628 memcpy(&pcm[fsize], &data[0], reqasize - fsize);
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
629 data += reqasize - fsize;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
630 data_size -= reqasize - fsize;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
631 }
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
632 dv_inject_audio(c, &pcm[0], *frame);
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
633 c->has_audio = 1;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
634 }
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
635
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
636 /* 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
637 if (fifo_size(&c->audio_data, c->audio_data.rptr) + data_size >= 100*AVCODEC_MAX_AUDIO_FRAME_SIZE)
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
638 fprintf(stderr, "Can't process DV frame #%d. Insufficient video data or severe sync problem.\n", c->frames);
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
639 fifo_write(&c->audio_data, (uint8_t *)data, data_size, &c->audio_data.wptr);
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
640 }
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
641
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
642 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
643 }
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
644
262
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
645 DVMuxContext* dv_init_mux(AVFormatContext* s)
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
646 {
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
647 DVMuxContext *c;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
648 AVStream *vst;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
649 AVStream *ast;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
650
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
651 c = av_mallocz(sizeof(DVMuxContext));
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
652 if (!c)
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
653 return NULL;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
654
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
655 if (s->nb_streams != 2)
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
656 goto bail_out;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
657
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
658 /* We have to sort out where audio and where video stream is */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
659 if (s->streams[0]->codec.codec_type == CODEC_TYPE_VIDEO &&
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
660 s->streams[1]->codec.codec_type == CODEC_TYPE_AUDIO) {
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
661 vst = s->streams[0];
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
662 ast = s->streams[1];
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
663 }
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
664 else if (s->streams[1]->codec.codec_type == CODEC_TYPE_VIDEO &&
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
665 s->streams[0]->codec.codec_type == CODEC_TYPE_AUDIO) {
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
666 vst = s->streams[1];
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
667 ast = s->streams[0];
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
668 } else
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
669 goto bail_out;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
670
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
671 /* Some checks -- DV format is very picky about its incoming streams */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
672 if (vst->codec.codec_id != CODEC_ID_DVVIDEO ||
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
673 ast->codec.codec_id != CODEC_ID_PCM_S16LE)
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
674 goto bail_out;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
675 if (ast->codec.sample_rate != 48000 ||
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
676 ast->codec.channels != 2)
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
677 goto bail_out;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
678
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
679 c->sys = dv_codec_profile(&vst->codec);
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
680 if (!c->sys)
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
681 goto bail_out;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
682
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
683 /* Ok, everything seems to be in working order */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
684 c->frames = 0;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
685 c->has_audio = c->has_video = 0;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
686 c->start_time = time(NULL);
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
687 c->aspect = 0; /* 4:3 is the default */
288
981b0b3c95dd AVRational
michael
parents: 273
diff changeset
688 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
689 c->aspect = 0x07;
37
8f76666c71c2 DV audio decoder by Roman Shaposhnick
bellard
parents: 28
diff changeset
690
262
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
691 if (fifo_init(&c->audio_data, 100*AVCODEC_MAX_AUDIO_FRAME_SIZE) < 0)
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
692 goto bail_out;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
693
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
694 dv_format_frame(c, &c->frame_buf[0]);
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
695
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
696 return c;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
697
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
698 bail_out:
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
699 av_free(c);
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
700 return NULL;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
701 }
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
702
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
703 void dv_delete_mux(DVMuxContext *c)
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
704 {
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
705 fifo_free(&c->audio_data);
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
706 }
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
707
296
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
708 DVDemuxContext* dv_init_demux(AVFormatContext *s)
262
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
709 {
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
710 DVDemuxContext *c;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
711
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
712 c = av_mallocz(sizeof(DVDemuxContext));
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
713 if (!c)
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
714 return NULL;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
715
296
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
716 c->vst = av_new_stream(s, 0);
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
717 c->ast[0] = av_new_stream(s, 0);
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
718 if (!c->vst || !c->ast[0])
262
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
719 goto fail;
296
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
720 c->fctx = s;
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
721 c->ast[1] = NULL;
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
722 c->ach = 0;
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
723 c->audio_pkt[0].size = 0;
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
724 c->audio_pkt[1].size = 0;
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
725
262
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
726 c->vst->codec.codec_type = CODEC_TYPE_VIDEO;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
727 c->vst->codec.codec_id = CODEC_ID_DVVIDEO;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
728 c->vst->codec.bit_rate = 25000000;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
729
296
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
730 c->ast[0]->codec.codec_type = CODEC_TYPE_AUDIO;
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
731 c->ast[0]->codec.codec_id = CODEC_ID_PCM_S16LE;
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
732
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
733 s->ctx_flags |= AVFMTCTX_NOHEADER;
262
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 return c;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
736
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
737 fail:
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
738 if (c->vst)
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
739 av_free(c->vst);
296
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
740 if (c->ast[0])
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
741 av_free(c->ast[0]);
262
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
742 av_free(c);
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
743 return NULL;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
744 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
745
58
b1dd147434af DV packet copy fix by Roman Shaposhnick
bellard
parents: 37
diff changeset
746 static void __destruct_pkt(struct AVPacket *pkt)
b1dd147434af DV packet copy fix by Roman Shaposhnick
bellard
parents: 37
diff changeset
747 {
b1dd147434af DV packet copy fix by Roman Shaposhnick
bellard
parents: 37
diff changeset
748 pkt->data = NULL; pkt->size = 0;
b1dd147434af DV packet copy fix by Roman Shaposhnick
bellard
parents: 37
diff changeset
749 return;
b1dd147434af DV packet copy fix by Roman Shaposhnick
bellard
parents: 37
diff changeset
750 }
b1dd147434af DV packet copy fix by Roman Shaposhnick
bellard
parents: 37
diff changeset
751
262
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
752 int dv_get_packet(DVDemuxContext *c, AVPacket *pkt)
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
753 {
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
754 int size = -1;
296
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
755 int i;
262
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
756
296
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
757 for (i=0; i<c->ach; i++) {
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
758 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
759 *pkt = c->audio_pkt[i];
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
760 c->audio_pkt[i].size = 0;
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
761 size = pkt->size;
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
762 break;
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
763 }
262
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
764 }
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 return size;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
767 }
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
768
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
769 int dv_produce_packet(DVDemuxContext *c, AVPacket *pkt,
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
770 uint8_t* buf, int buf_size)
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
771 {
296
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
772 int size, i;
262
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
773
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
774 if (buf_size < 4 || buf_size < dv_frame_profile(buf)->frame_size)
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
775 return -1; /* Broken frame, or not enough data */
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 /* Queueing audio packet */
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
778 /* 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
779 size = dv_extract_audio_info(c, buf);
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
780 c->audio_pkt[0].data = c->audio_pkt[1].data = NULL;
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
781 for (i=0; i<c->ach; i++) {
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
782 if (av_new_packet(&c->audio_pkt[i], size) < 0)
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
783 return AVERROR_NOMEM;
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
784 c->audio_pkt[i].stream_index = c->ast[i]->index;
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
785 }
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
786 dv_extract_audio(buf, c->audio_pkt[0].data, c->audio_pkt[1].data);
262
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
787
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
788 /* 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
789 size = dv_extract_video_info(c, buf);
262
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
790 av_init_packet(pkt);
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
791 pkt->destruct = __destruct_pkt;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
792 pkt->data = buf;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
793 pkt->size = size;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
794 pkt->flags |= PKT_FLAG_KEY;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
795 pkt->stream_index = c->vst->id;
296
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
796
262
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
797 return size;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
798 }
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
799
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
800 /************************************************************
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
801 * 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
802 ************************************************************/
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
803
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
804 typedef struct RawDVContext {
296
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
805 uint8_t buf[144000];
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
806 DVDemuxContext* dv_demux;
262
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
807 } RawDVContext;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
808
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
809 static int dv_read_header(AVFormatContext *s,
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
810 AVFormatParameters *ap)
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
811 {
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
812 RawDVContext *c = s->priv_data;
296
252946de6d3f * DV demuxer is now capable of decoding auxilary audio stream. So,
romansh
parents: 288
diff changeset
813 c->dv_demux = dv_init_demux(s);
262
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
814
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
815 return c->dv_demux ? 0 : -1;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
816 }
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
817
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
818
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
819 static int dv_read_packet(AVFormatContext *s, AVPacket *pkt)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
820 {
262
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
821 int size;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
822 RawDVContext *c = s->priv_data;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
823
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
824 size = dv_get_packet(c->dv_demux, pkt);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
825
262
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
826 if (size < 0) {
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
827 if (get_buffer(&s->pb, c->buf, 4) <= 0)
37
8f76666c71c2 DV audio decoder by Roman Shaposhnick
bellard
parents: 28
diff changeset
828 return -EIO;
262
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
829
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
830 size = dv_frame_profile(c->buf)->frame_size;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
831 if (get_buffer(&s->pb, c->buf + 4, size - 4) <= 0)
37
8f76666c71c2 DV audio decoder by Roman Shaposhnick
bellard
parents: 28
diff changeset
832 return -EIO;
262
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
833
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
834 size = dv_produce_packet(c->dv_demux, pkt, c->buf, size);
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
835 }
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
836
262
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
837 return size;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
838 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
839
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
840 static int dv_read_close(AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
841 {
262
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
842 RawDVContext *c = s->priv_data;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
843 av_free(c->dv_demux);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
844 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
845 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
846
262
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
847 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
848 {
262
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
849 s->priv_data = dv_init_mux(s);
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
850 if (!s->priv_data) {
203
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents: 119
diff changeset
851 fprintf(stderr, "Can't initialize DV format!\n"
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents: 119
diff changeset
852 "Make sure that you supply exactly two streams:\n"
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents: 119
diff changeset
853 " video: 25fps or 29.97fps, audio: 2ch/48Khz/PCM\n");
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents: 119
diff changeset
854 return -1;
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents: 119
diff changeset
855 }
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents: 119
diff changeset
856 return 0;
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents: 119
diff changeset
857 }
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents: 119
diff changeset
858
262
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
859 static int dv_write_packet(struct AVFormatContext *s,
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
860 int stream_index,
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
861 const uint8_t *buf, int size, int64_t pts)
203
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents: 119
diff changeset
862 {
262
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
863 uint8_t* frame;
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
864 int fsize;
203
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents: 119
diff changeset
865
262
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
866 fsize = dv_assemble_frame((DVMuxContext *)s->priv_data, s->streams[stream_index],
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
867 buf, size, &frame);
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
868 if (fsize > 0) {
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
869 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
870 put_flush_packet(&s->pb);
262
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
871 }
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
872 return fsize;
203
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents: 119
diff changeset
873 }
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents: 119
diff changeset
874
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents: 119
diff changeset
875 /*
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents: 119
diff changeset
876 * 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
877 * E.g. video data without enough audio to write the complete frame.
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents: 119
diff changeset
878 * Currently we simply drop the last frame. I don't know whether this
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents: 119
diff changeset
879 * 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
880 */
262
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
881 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
882 {
262
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
883 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
884 return 0;
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents: 119
diff changeset
885 }
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents: 119
diff changeset
886
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
887 static AVInputFormat dv_iformat = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
888 "dv",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
889 "DV video format",
262
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
890 sizeof(RawDVContext),
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
891 NULL,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
892 dv_read_header,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
893 dv_read_packet,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
894 dv_read_close,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
895 .extensions = "dv",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
896 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
897
262
f174d9c00bce * DV handling was streamlined for both muxing/demuxing and
romansh
parents: 241
diff changeset
898 static AVOutputFormat dv_oformat = {
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
899 "dv",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
900 "DV video format",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
901 NULL,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
902 "dv",
203
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents: 119
diff changeset
903 sizeof(DVMuxContext),
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents: 119
diff changeset
904 CODEC_ID_PCM_S16LE,
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
905 CODEC_ID_DVVIDEO,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
906 dv_write_header,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
907 dv_write_packet,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
908 dv_write_trailer,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
909 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
910
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
911 int dv_init(void)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
912 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
913 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
914 av_register_output_format(&dv_oformat);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
915 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
916 }