annotate dvcore.c @ 221:fa80efcf8e39 libavformat

padding fix
author michaelni
date Sat, 06 Sep 2003 16:29:05 +0000
parents 89a78842f6c2
children 23a6daaa93dd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
203
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
1 /*
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
2 * DV format muxer/demuxer
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
3 * Copyright (c) 2003 Roman Shaposhnik
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
4 *
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
5 * Many thanks to Dan Dennedy <dan@dennedy.org> for providing wealth
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
6 * of DV technical info, and SMPTE 314M specification.
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
7 *
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
8 * This library is free software; you can redistribute it and/or
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
9 * modify it under the terms of the GNU Lesser General Public
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
10 * License as published by the Free Software Foundation; either
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
11 * version 2 of the License, or (at your option) any later version.
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
12 *
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
13 * This library is distributed in the hope that it will be useful,
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
16 * Lesser General Public License for more details.
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
17 *
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
18 * You should have received a copy of the GNU Lesser General Public
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
19 * License along with this library; if not, write to the Free Software
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
21 */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
22 #include "avformat.h"
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
23 #include "dvcore.h"
213
89a78842f6c2 localtime_r patch by (Glenn Maynard <g_sf at zewt dot org>)
michaelni
parents: 203
diff changeset
24 #include "localtime_r.h"
203
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
25
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
26 /*
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
27 * The reason why the following three big ugly looking tables are
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
28 * here is my lack of DV spec IEC 61834. The tables were basically
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
29 * constructed to make code that places packs in SSYB, VAUX and
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
30 * AAUX blocks very simple and table-driven. They conform to the
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
31 * SMPTE 314M and the output of my personal DV camcorder, neither
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
32 * of which is sufficient for a reliable DV stream producing. Thus
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
33 * while code is still in development I'll be gathering input from
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
34 * people with different DV equipment and modifying the tables to
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
35 * accommodate all the quirks. Later on, if possible, some of them
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
36 * will be folded into smaller tables and/or switch-if logic. For
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
37 * now, my only excuse is -- they don't eat up that much of a space.
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
38 */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
39
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
40 static const int dv_ssyb_packs_dist[12][6] = {
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
41 { 0x13, 0x13, 0x13, 0x13, 0x13, 0x13 },
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
42 { 0x13, 0x13, 0x13, 0x13, 0x13, 0x13 },
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
43 { 0x13, 0x13, 0x13, 0x13, 0x13, 0x13 },
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
44 { 0x13, 0x13, 0x13, 0x13, 0x13, 0x13 },
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
45 { 0x13, 0x13, 0x13, 0x13, 0x13, 0x13 },
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
46 { 0x13, 0x13, 0x13, 0x13, 0x13, 0x13 },
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
47 { 0x13, 0x62, 0x63, 0x13, 0x62, 0x63 },
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
48 { 0x13, 0x62, 0x63, 0x13, 0x62, 0x63 },
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
49 { 0x13, 0x62, 0x63, 0x13, 0x62, 0x63 },
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
50 { 0x13, 0x62, 0x63, 0x13, 0x62, 0x63 },
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
51 { 0x13, 0x62, 0x63, 0x13, 0x62, 0x63 },
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
52 { 0x13, 0x62, 0x63, 0x13, 0x62, 0x63 },
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
53 };
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
54
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
55 static const int dv_vaux_packs_dist[12][15] = {
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
56 { 0x60, 0x61, 0x62, 0x63, 0xff, 0xff, 0xff, 0xff, 0xff,
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
57 0x60, 0x61, 0x62, 0x63, 0xff, 0xff },
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
58 { 0x60, 0x61, 0x62, 0x63, 0xff, 0xff, 0xff, 0xff, 0xff,
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
59 0x60, 0x61, 0x62, 0x63, 0xff, 0xff },
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
60 { 0x60, 0x61, 0x62, 0x63, 0xff, 0xff, 0xff, 0xff, 0xff,
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
61 0x60, 0x61, 0x62, 0x63, 0xff, 0xff },
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
62 { 0x60, 0x61, 0x62, 0x63, 0xff, 0xff, 0xff, 0xff, 0xff,
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
63 0x60, 0x61, 0x62, 0x63, 0xff, 0xff },
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
64 { 0x60, 0x61, 0x62, 0x63, 0xff, 0xff, 0xff, 0xff, 0xff,
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
65 0x60, 0x61, 0x62, 0x63, 0xff, 0xff },
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
66 { 0x60, 0x61, 0x62, 0x63, 0xff, 0xff, 0xff, 0xff, 0xff,
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
67 0x60, 0x61, 0x62, 0x63, 0xff, 0xff },
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
68 { 0x60, 0x61, 0x62, 0x63, 0xff, 0xff, 0xff, 0xff, 0xff,
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
69 0x60, 0x61, 0x62, 0x63, 0xff, 0xff },
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
70 { 0x60, 0x61, 0x62, 0x63, 0xff, 0xff, 0xff, 0xff, 0xff,
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
71 0x60, 0x61, 0x62, 0x63, 0xff, 0xff },
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
72 { 0x60, 0x61, 0x62, 0x63, 0xff, 0xff, 0xff, 0xff, 0xff,
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
73 0x60, 0x61, 0x62, 0x63, 0xff, 0xff },
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
74 { 0x60, 0x61, 0x62, 0x63, 0xff, 0xff, 0xff, 0xff, 0xff,
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
75 0x60, 0x61, 0x62, 0x63, 0xff, 0xff },
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
76 { 0x60, 0x61, 0x62, 0x63, 0xff, 0xff, 0xff, 0xff, 0xff,
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
77 0x60, 0x61, 0x62, 0x63, 0xff, 0xff },
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
78 { 0x60, 0x61, 0x62, 0x63, 0xff, 0xff, 0xff, 0xff, 0xff,
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
79 0x60, 0x61, 0x62, 0x63, 0xff, 0xff },
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
80 };
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
81
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
82 static const int dv_aaux_packs_dist[12][9] = {
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
83 { 0xff, 0xff, 0xff, 0x50, 0x51, 0x52, 0x53, 0xff, 0xff },
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
84 { 0x50, 0x51, 0x52, 0x53, 0xff, 0xff, 0xff, 0xff, 0xff },
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
85 { 0xff, 0xff, 0xff, 0x50, 0x51, 0x52, 0x53, 0xff, 0xff },
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
86 { 0x50, 0x51, 0x52, 0x53, 0xff, 0xff, 0xff, 0xff, 0xff },
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
87 { 0xff, 0xff, 0xff, 0x50, 0x51, 0x52, 0x53, 0xff, 0xff },
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
88 { 0x50, 0x51, 0x52, 0x53, 0xff, 0xff, 0xff, 0xff, 0xff },
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
89 { 0xff, 0xff, 0xff, 0x50, 0x51, 0x52, 0x53, 0xff, 0xff },
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
90 { 0x50, 0x51, 0x52, 0x53, 0xff, 0xff, 0xff, 0xff, 0xff },
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
91 { 0xff, 0xff, 0xff, 0x50, 0x51, 0x52, 0x53, 0xff, 0xff },
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
92 { 0x50, 0x51, 0x52, 0x53, 0xff, 0xff, 0xff, 0xff, 0xff },
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
93 { 0xff, 0xff, 0xff, 0x50, 0x51, 0x52, 0x53, 0xff, 0xff },
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
94 { 0x50, 0x51, 0x52, 0x53, 0xff, 0xff, 0xff, 0xff, 0xff },
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
95 };
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
96
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
97 enum dv_section_type {
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
98 dv_sect_header = 0x1f,
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
99 dv_sect_subcode = 0x3f,
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
100 dv_sect_vaux = 0x56,
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
101 dv_sect_audio = 0x76,
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
102 dv_sect_video = 0x96,
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
103 };
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
104
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
105 enum dv_pack_type {
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
106 dv_header525 = 0x3f, /* see dv_write_pack for important details on */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
107 dv_header625 = 0xbf, /* these two packs */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
108 dv_timecode = 0x13,
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
109 dv_audio_source = 0x50,
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
110 dv_audio_control = 0x51,
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
111 dv_audio_recdate = 0x52,
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
112 dv_audio_rectime = 0x53,
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
113 dv_video_source = 0x60,
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
114 dv_video_control = 0x61,
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
115 dv_viedo_recdate = 0x62,
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
116 dv_video_rectime = 0x63,
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
117 dv_unknown_pack = 0xff,
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
118 };
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
119
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
120 static const uint16_t dv_audio_shuffle525[10][9] = {
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
121 { 0, 30, 60, 20, 50, 80, 10, 40, 70 }, /* 1st channel */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
122 { 6, 36, 66, 26, 56, 86, 16, 46, 76 },
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
123 { 12, 42, 72, 2, 32, 62, 22, 52, 82 },
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
124 { 18, 48, 78, 8, 38, 68, 28, 58, 88 },
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
125 { 24, 54, 84, 14, 44, 74, 4, 34, 64 },
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
126
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
127 { 1, 31, 61, 21, 51, 81, 11, 41, 71 }, /* 2nd channel */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
128 { 7, 37, 67, 27, 57, 87, 17, 47, 77 },
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
129 { 13, 43, 73, 3, 33, 63, 23, 53, 83 },
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
130 { 19, 49, 79, 9, 39, 69, 29, 59, 89 },
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
131 { 25, 55, 85, 15, 45, 75, 5, 35, 65 },
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
132 };
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
133
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
134 static const uint16_t dv_audio_shuffle625[12][9] = {
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
135 { 0, 36, 72, 26, 62, 98, 16, 52, 88}, /* 1st channel */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
136 { 6, 42, 78, 32, 68, 104, 22, 58, 94},
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
137 { 12, 48, 84, 2, 38, 74, 28, 64, 100},
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
138 { 18, 54, 90, 8, 44, 80, 34, 70, 106},
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
139 { 24, 60, 96, 14, 50, 86, 4, 40, 76},
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
140 { 30, 66, 102, 20, 56, 92, 10, 46, 82},
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
141
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
142 { 1, 37, 73, 27, 63, 99, 17, 53, 89}, /* 2nd channel */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
143 { 7, 43, 79, 33, 69, 105, 23, 59, 95},
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
144 { 13, 49, 85, 3, 39, 75, 29, 65, 101},
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
145 { 19, 55, 91, 9, 45, 81, 35, 71, 107},
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
146 { 25, 61, 97, 15, 51, 87, 5, 41, 77},
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
147 { 31, 67, 103, 21, 57, 93, 11, 47, 83},
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
148 };
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
149
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
150 static const int dv_audio_frequency[3] = {
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
151 48000, 44100, 32000,
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
152 };
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
153
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
154 const DVprofile dv_profiles[2] = {
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
155 { .dsf = 0,
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
156 .frame_size = 120000, /* 525/60 system (NTSC) */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
157 .difseg_size = 10,
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
158 .frame_rate = 30000,
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
159 .ltc_divisor = 30,
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
160 .frame_rate_base = 1001,
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
161 .height = 480,
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
162 /* .video_place = dv_place_411, */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
163 .audio_stride = 90,
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
164 .audio_min_samples = { 1580, 1452, 1053 }, /* for 48, 44.1 and 32Khz */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
165 .audio_samples_dist = { 1602, 1601, 1602, 1601, 1602 },
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
166 .audio_shuffle = dv_audio_shuffle525,
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
167 },
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
168 { .dsf = 1,
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
169 .frame_size = 144000, /* 625/50 system (PAL) */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
170 .difseg_size = 12,
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
171 .frame_rate = 25,
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
172 .frame_rate_base = 1,
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
173 .ltc_divisor = 25,
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
174 .height = 576,
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
175 /* .video_place = dv_place_420, */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
176 .audio_stride = 108,
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
177 .audio_min_samples = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32Khz */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
178 .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 },
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
179 .audio_shuffle = dv_audio_shuffle525,
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
180 }
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
181 };
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
182
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
183 static inline uint16_t dv_audio_12to16(uint16_t sample)
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
184 {
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
185 uint16_t shift, result;
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
186
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
187 sample = (sample < 0x800) ? sample : sample | 0xf000;
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
188 shift = (sample & 0xf00) >> 8;
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
189
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
190 if (shift < 0x2 || shift > 0xd) {
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
191 result = sample;
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
192 } else if (shift < 0x8) {
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
193 shift--;
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
194 result = (sample - (256 * shift)) << shift;
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
195 } else {
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
196 shift = 0xe - shift;
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
197 result = ((sample + ((256 * shift) + 1)) << shift) - 1;
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
198 }
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
199
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
200 return result;
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
201 }
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
202
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
203 static int dv_write_pack(enum dv_pack_type pack_id, DVMuxContext *c, uint8_t* buf)
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
204 {
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
205 struct tm tc;
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
206 time_t ct;
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
207 int ltc_frame;
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
208
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
209 buf[0] = (uint8_t)pack_id;
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
210 switch (pack_id) {
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
211 case dv_header525: /* I can't imagine why these two weren't defined as real */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
212 case dv_header625: /* packs in SMPTE314M -- they definitely look like ones */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
213 buf[1] = 0xf8 | /* reserved -- always 1 */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
214 (0 & 0x07); /* APT: Track application ID */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
215 buf[2] = (0 << 7) | /* TF1: audio data is 0 - valid; 1 - invalid */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
216 (0x0f << 3) | /* reserved -- always 1 */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
217 (0 & 0x07); /* AP1: Audio application ID */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
218 buf[3] = (0 << 7) | /* TF2: video data is 0 - valid; 1 - invalid */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
219 (0x0f << 3) | /* reserved -- always 1 */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
220 (0 & 0x07); /* AP2: Video application ID */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
221 buf[4] = (0 << 7) | /* TF3: subcode(SSYB) is 0 - valid; 1 - invalid */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
222 (0x0f << 3) | /* reserved -- always 1 */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
223 (0 & 0x07); /* AP3: Subcode application ID */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
224 break;
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
225 case dv_timecode:
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
226 ct = (time_t)(c->frames / ((float)c->sys->frame_rate /
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
227 (float)c->sys->frame_rate_base));
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
228 localtime_r(&ct, &tc);
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
229 /*
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
230 * LTC drop-frame frame counter drops two frames (0 and 1) every
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
231 * minute, unless it is exactly divisible by 10
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
232 */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
233 ltc_frame = (c->frames + 2*ct/60 - 2*ct/600) % c->sys->ltc_divisor;
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
234 buf[1] = (0 << 7) | /* Color fame: 0 - unsync; 1 - sync mode */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
235 (1 << 6) | /* Drop frame timecode: 0 - nondrop; 1 - drop */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
236 ((ltc_frame / 10) << 4) | /* Tens of frames */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
237 (ltc_frame % 10); /* Units of frames */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
238 buf[2] = (1 << 7) | /* Biphase mark polarity correction: 0 - even; 1 - odd */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
239 ((tc.tm_sec / 10) << 4) | /* Tens of seconds */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
240 (tc.tm_sec % 10); /* Units of seconds */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
241 buf[3] = (1 << 7) | /* Binary group flag BGF0 */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
242 ((tc.tm_min / 10) << 4) | /* Tens of minutes */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
243 (tc.tm_min % 10); /* Units of minutes */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
244 buf[4] = (1 << 7) | /* Binary group flag BGF2 */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
245 (1 << 6) | /* Binary group flag BGF1 */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
246 ((tc.tm_hour / 10) << 4) | /* Tens of hours */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
247 (tc.tm_hour % 10); /* Units of hours */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
248 break;
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
249 case dv_audio_source: /* AAUX source pack */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
250 buf[1] = (0 << 7) | /* locked mode */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
251 (1 << 6) | /* reserved -- always 1 */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
252 (dv_audio_frame_size(c->sys, c->frames) -
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
253 c->sys->audio_min_samples[0]);
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
254 /* # of samples */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
255 buf[2] = (0 << 7) | /* multi-stereo */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
256 (0 << 5) | /* #of audio channels per block: 0 -- 1 channel */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
257 (0 << 4) | /* pair bit: 0 -- one pair of channels */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
258 0; /* audio mode */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
259 buf[3] = (1 << 7) | /* res */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
260 (1 << 6) | /* multi-language flag */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
261 (c->sys->dsf << 5) | /* system: 60fields/50fields */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
262 0; /* definition: 0 -- SD (525/625) */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
263 buf[4] = (1 << 7) | /* emphasis: 1 -- off */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
264 (0 << 6) | /* emphasis time constant: 0 -- reserved */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
265 (0 << 3) | /* frequency: 0 -- 48Khz, 1 -- 44,1Khz, 2 -- 32Khz */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
266 0; /* quantization: 0 -- 16bit linear, 1 -- 12bit nonlinear */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
267 break;
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
268 case dv_audio_control:
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
269 buf[1] = (0 << 6) | /* copy protection: 0 -- unrestricted */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
270 (1 << 4) | /* input source: 1 -- digital input */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
271 (3 << 2) | /* compression: 3 -- no information */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
272 0; /* misc. info/SMPTE emphasis off */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
273 buf[2] = (1 << 7) | /* recording start point: 1 -- no */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
274 (1 << 6) | /* recording end point: 1 -- no */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
275 (1 << 3) | /* recording mode: 1 -- original */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
276 7;
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
277 buf[3] = (1 << 7) | /* direction: 1 -- forward */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
278 0x20; /* speed */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
279 buf[4] = (1 << 7) | /* reserved -- always 1 */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
280 0x7f; /* genre category */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
281 break;
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
282 case dv_audio_recdate:
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
283 case dv_viedo_recdate: /* VAUX recording date */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
284 ct = c->start_time + (time_t)(c->frames /
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
285 ((float)c->sys->frame_rate / (float)c->sys->frame_rate_base));
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
286 localtime_r(&ct, &tc);
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
287 buf[1] = 0xff; /* ds, tm, tens of time zone, units of time zone */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
288 /* 0xff is very likely to be "unknown" */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
289 buf[2] = (3 << 6) | /* reserved -- always 1 */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
290 ((tc.tm_mday / 10) << 4) | /* Tens of day */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
291 (tc.tm_mday % 10); /* Units of day */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
292 buf[3] = /* we set high 4 bits to 0, shouldn't we set them to week? */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
293 (tc.tm_mon % 10); /* Units of month */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
294 buf[4] = (((tc.tm_year % 100) / 10) << 4) | /* Tens of year */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
295 (tc.tm_year % 10); /* Units of year */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
296 break;
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
297 case dv_audio_rectime: /* AAUX recording time */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
298 case dv_video_rectime: /* VAUX recording time */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
299 ct = c->start_time + (time_t)(c->frames /
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
300 ((float)c->sys->frame_rate / (float)c->sys->frame_rate_base));
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
301 localtime_r(&ct, &tc);
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
302 buf[1] = (3 << 6) | /* reserved -- always 1 */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
303 0x3f; /* tens of frame, units of frame: 0x3f - "unknown" ? */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
304 buf[2] = (1 << 7) | /* reserved -- always 1 */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
305 ((tc.tm_sec / 10) << 4) | /* Tens of seconds */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
306 (tc.tm_sec % 10); /* Units of seconds */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
307 buf[3] = (1 << 7) | /* reserved -- always 1 */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
308 ((tc.tm_min / 10) << 4) | /* Tens of minutes */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
309 (tc.tm_min % 10); /* Units of minutes */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
310 buf[4] = (3 << 6) | /* reserved -- always 1 */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
311 ((tc.tm_hour / 10) << 4) | /* Tens of hours */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
312 (tc.tm_hour % 10); /* Units of hours */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
313 break;
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
314 case dv_video_source:
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
315 buf[1] = 0xff; /* reserved -- always 1 */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
316 buf[2] = (1 << 7) | /* B/W: 0 - b/w, 1 - color */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
317 (1 << 6) | /* following CLF is valid - 0, invalid - 1 */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
318 (3 << 4) | /* CLF: color frames id (see ITU-R BT.470-4) */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
319 0xf; /* reserved -- always 1 */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
320 buf[3] = (3 << 6) | /* reserved -- always 1 */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
321 (c->sys->dsf << 5) | /* system: 60fields/50fields */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
322 0; /* signal type video compression */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
323 buf[4] = 0xff; /* VISC: 0xff -- no information */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
324 break;
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
325 case dv_video_control:
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
326 buf[1] = (0 << 6) | /* Copy generation management (CGMS) 0 -- free */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
327 0x3f; /* reserved -- always 1 */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
328 buf[2] = 0xc8 | /* reserved -- always b11001xxx */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
329 c->aspect;
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
330 buf[3] = (1 << 7) | /* Frame/field flag 1 -- frame, 0 -- field */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
331 (1 << 6) | /* First/second field flag 0 -- field 2, 1 -- field 1 */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
332 (1 << 5) | /* Frame change flag 0 -- same picture as before, 1 -- different */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
333 (1 << 4) | /* 1 - interlaced, 0 - noninterlaced */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
334 0xc; /* reserved -- always b1100 */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
335 buf[4] = 0xff; /* reserved -- always 1 */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
336 break;
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
337 default:
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
338 buf[1] = buf[2] = buf[3] = buf[4] = 0xff;
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
339 }
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
340 return 5;
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
341 }
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
342
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
343 static inline int dv_write_dif_id(enum dv_section_type t, uint8_t seq_num,
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
344 uint8_t dif_num, uint8_t* buf)
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
345 {
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
346 buf[0] = (uint8_t)t; /* Section type */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
347 buf[1] = (seq_num<<4) | /* DIF seq number 0-9 for 525/60; 0-11 for 625/50 */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
348 (0 << 3) | /* FSC: for 50Mb/s 0 - first channel; 1 - second */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
349 7; /* reserved -- always 1 */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
350 buf[2] = dif_num; /* DIF block number Video: 0-134, Audio: 0-8 */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
351 return 3;
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
352 }
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
353
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
354 static inline int dv_write_ssyb_id(uint8_t syb_num, uint8_t fr, uint8_t* buf)
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
355 {
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
356 if (syb_num == 0 || syb_num == 6) {
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
357 buf[0] = (fr<<7) | /* FR ID 1 - first half of each channel; 0 - second */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
358 (0<<4) | /* AP3 (Subcode application ID) */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
359 0x0f; /* reserved -- always 1 */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
360 }
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
361 else if (syb_num == 11) {
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
362 buf[0] = (fr<<7) | /* FR ID 1 - first half of each channel; 0 - second */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
363 0x7f; /* reserved -- always 1 */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
364 }
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
365 else {
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
366 buf[0] = (fr<<7) | /* FR ID 1 - first half of each channel; 0 - second */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
367 (0<<4) | /* APT (Track application ID) */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
368 0x0f; /* reserved -- always 1 */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
369 }
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
370 buf[1] = 0xf0 | /* reserved -- always 1 */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
371 (syb_num & 0x0f); /* SSYB number 0 - 11 */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
372 buf[2] = 0xff; /* reserved -- always 1 */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
373 return 3;
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
374 }
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
375
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
376 void dv_format_frame(DVMuxContext *c, uint8_t* buf)
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
377 {
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
378 int i, j, k;
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
379
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
380 for (i = 0; i < c->sys->difseg_size; i++) {
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
381 memset(buf, 0xff, 80 * 6); /* First 6 DIF blocks are for control data */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
382
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
383 /* DV header: 1DIF */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
384 buf += dv_write_dif_id(dv_sect_header, i, 0, buf);
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
385 buf += dv_write_pack((c->sys->dsf ? dv_header625 : dv_header525), c, buf);
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
386 buf += 72; /* unused bytes */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
387
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
388 /* DV subcode: 2DIFs */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
389 for (j = 0; j < 2; j++) {
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
390 buf += dv_write_dif_id( dv_sect_subcode, i, j, buf);
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
391 for (k = 0; k < 6; k++) {
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
392 buf += dv_write_ssyb_id(k, (i < c->sys->difseg_size/2), buf);
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
393 buf += dv_write_pack(dv_ssyb_packs_dist[i][k], c, buf);
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
394 }
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
395 buf += 29; /* unused bytes */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
396 }
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
397
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
398 /* DV VAUX: 3DIFs */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
399 for (j = 0; j < 3; j++) {
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
400 buf += dv_write_dif_id(dv_sect_vaux, i, j, buf);
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
401 for (k = 0; k < 15 ; k++)
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
402 buf += dv_write_pack(dv_vaux_packs_dist[i][k], c, buf);
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
403 buf += 2; /* unused bytes */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
404 }
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
405
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
406 /* DV Audio/Video: 135 Video DIFs + 9 Audio DIFs */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
407 for (j = 0; j < 135; j++) {
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
408 if (j%15 == 0) {
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
409 buf += dv_write_dif_id(dv_sect_audio, i, j/15, buf);
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
410 buf += dv_write_pack(dv_aaux_packs_dist[i][j/15], c, buf);
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
411 buf += 72; /* shuffled PCM audio */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
412 }
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
413 buf += dv_write_dif_id(dv_sect_video, i, j, buf);
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
414 buf += 77; /* 1 video macro block: 1 bytes control
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
415 4 * 14 bytes Y 8x8 data
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
416 10 bytes Cr 8x8 data
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
417 10 bytes Cb 8x8 data */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
418 }
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
419 }
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
420 }
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
421
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
422 void dv_inject_audio(DVMuxContext *c, uint8_t* pcm, uint8_t* frame_ptr)
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
423 {
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
424 int i, j, d, of;
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
425 for (i = 0; i < c->sys->difseg_size; i++) {
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
426 frame_ptr += 6 * 80; /* skip DIF segment header */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
427 for (j = 0; j < 9; j++) {
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
428 for (d = 8; d < 80; d+=2) {
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
429 of = c->sys->audio_shuffle[i][j] + (d - 8)/2 * c->sys->audio_stride;
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
430 frame_ptr[d] = pcm[of*2+1]; // FIXME: may be we have to admit
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
431 frame_ptr[d+1] = pcm[of*2]; // that DV is a big endian PCM
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
432 }
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
433 frame_ptr += 16 * 80; /* 15 Video DIFs + 1 Audio DIF */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
434 }
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
435 }
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
436 }
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
437
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
438 void dv_inject_video(DVMuxContext *c, uint8_t* video_data, uint8_t* frame_ptr)
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
439 {
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
440 int i, j;
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
441 int ptr = 0;
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
442
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
443 for (i = 0; i < c->sys->difseg_size; i++) {
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
444 ptr += 6 * 80; /* skip DIF segment header */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
445 for (j = 0; j < 135; j++) {
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
446 if (j%15 == 0)
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
447 ptr += 80; /* skip Audio DIF */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
448 ptr += 3;
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
449 memcpy(frame_ptr + ptr, video_data + ptr, 77);
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
450 ptr += 77;
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
451 }
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
452 }
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
453 }
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
454
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
455 int dv_audio_frame_size(const DVprofile* sys, int frame)
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
456 {
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
457 return sys->audio_samples_dist[frame % (sizeof(sys->audio_samples_dist)/
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
458 sizeof(sys->audio_samples_dist[0]))];
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
459 }
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
460
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
461 const DVprofile* dv_frame_profile(uint8_t* frame)
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
462 {
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
463 return &dv_profiles[!!(frame[3] & 0x80)]; /* Header, DSF flag */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
464 }
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
465
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
466 /*
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
467 * This is the dumbest implementation of all -- it simply looks at
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
468 * a fixed offset and if pack isn't there -- fails. We might want
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
469 * to have a fallback mechanism for complete search of missing packs.
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
470 */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
471 const uint8_t* dv_extract_pack(uint8_t* frame, enum dv_pack_type t)
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
472 {
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
473 int offs;
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
474
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
475 switch (t) {
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
476 case dv_audio_source:
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
477 offs = (80*6 + 80*16*3 + 3);
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
478 break;
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
479 case dv_audio_control:
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
480 offs = (80*6 + 80*16*4 + 3);
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
481 break;
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
482 case dv_video_control:
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
483 offs = (80*5 + 48 + 5);
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
484 break;
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
485 default:
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
486 return NULL;
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
487 }
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
488
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
489 return (frame[offs] == t ? &frame[offs] : NULL);
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
490 }
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
491
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
492 /*
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
493 * There's a couple of assumptions being made here:
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
494 * 1. By default we silence erroneous (0x8000/16bit 0x800/12bit) audio samples.
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
495 * We can pass them upwards when ffmpeg will be ready to deal with them.
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
496 * 2. We don't do software emphasis.
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
497 * 3. Audio is always returned as 16bit linear samples: 12bit nonlinear samples
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
498 * are converted into 16bit linear ones.
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
499 */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
500 int dv_extract_audio(uint8_t* frame, uint8_t* pcm, AVCodecContext* avctx)
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
501 {
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
502 int size, i, j, d, of, smpls, freq, quant;
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
503 uint16_t lc, rc;
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
504 const DVprofile* sys;
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
505 const uint8_t* as_pack;
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
506
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
507 as_pack = dv_extract_pack(frame, dv_audio_source);
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
508 if (!as_pack) /* No audio ? */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
509 return 0;
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
510
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
511 sys = dv_frame_profile(frame);
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
512 smpls = as_pack[1] & 0x3f; /* samples in this frame - min. samples */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
513 freq = (as_pack[4] >> 3) & 0x07; /* 0 - 48KHz, 1 - 44,1kHz, 2 - 32 kHz */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
514 quant = as_pack[4] & 0x07; /* 0 - 16bit linear, 1 - 12bit nonlinear */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
515
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
516 if (quant > 1)
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
517 return -1; /* Unsupported quantization */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
518
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
519 avctx->sample_rate = dv_audio_frequency[freq];
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
520 avctx->channels = 2;
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
521 avctx->bit_rate = avctx->channels * avctx->sample_rate * 16;
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
522 // What about:
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
523 // avctx->frame_size =
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
524
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
525 size = (sys->audio_min_samples[freq] + smpls) * 4; /* 2ch, 2bytes */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
526
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
527 /* for each DIF segment */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
528 for (i = 0; i < sys->difseg_size; i++) {
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
529 frame += 6 * 80; /* skip DIF segment header */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
530 for (j = 0; j < 9; j++) {
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
531 for (d = 8; d < 80; d += 2) {
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
532 if (quant == 0) { /* 16bit quantization */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
533 of = sys->audio_shuffle[i][j] + (d - 8)/2 * sys->audio_stride;
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
534 pcm[of*2] = frame[d+1]; // FIXME: may be we have to admit
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
535 pcm[of*2+1] = frame[d]; // that DV is a big endian PCM
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
536 if (pcm[of*2+1] == 0x80 && pcm[of*2] == 0x00)
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
537 pcm[of*2+1] = 0;
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
538 } else { /* 12bit quantization */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
539 if (i >= sys->difseg_size/2)
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
540 goto out; /* We're not doing 4ch at this time */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
541
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
542 lc = ((uint16_t)frame[d] << 4) |
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
543 ((uint16_t)frame[d+2] >> 4);
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
544 rc = ((uint16_t)frame[d+1] << 4) |
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
545 ((uint16_t)frame[d+2] & 0x0f);
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
546 lc = (lc == 0x800 ? 0 : dv_audio_12to16(lc));
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
547 rc = (rc == 0x800 ? 0 : dv_audio_12to16(rc));
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
548
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
549 of = sys->audio_shuffle[i][j] + (d - 8)/3 * sys->audio_stride;
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
550 pcm[of*2] = lc & 0xff; // FIXME: may be we have to admit
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
551 pcm[of*2+1] = lc >> 8; // that DV is a big endian PCM
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
552 of = sys->audio_shuffle[i+sys->difseg_size/2][j] +
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
553 (d - 8)/3 * sys->audio_stride;
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
554 pcm[of*2] = rc & 0xff; // FIXME: may be we have to admit
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
555 pcm[of*2+1] = rc >> 8; // that DV is a big endian PCM
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
556 ++d;
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
557 }
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
558 }
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
559
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
560 frame += 16 * 80; /* 15 Video DIFs + 1 Audio DIF */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
561 }
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
562 }
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
563
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
564 out:
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
565 return size;
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
566 }
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
567
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
568 /* FIXME: The following three functions could be underengineered ;-) */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
569 void dv_assemble_frame(DVMuxContext *c, uint8_t* video, uint8_t* audio, int asize)
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
570 {
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
571 uint8_t pcm[8192];
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
572 uint8_t* frame = &c->frame_buf[0];
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
573 int fsize, reqasize;
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
574
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
575 if (c->has_audio && c->has_video) { /* must be a stale frame */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
576 dv_format_frame(c, frame);
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
577 c->frames++;
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
578 c->has_audio = c->has_video = 0;
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
579 }
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
580
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
581 if (video) {
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
582 /* FIXME: we have to have more sensible approach than this one */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
583 if (c->has_video)
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
584 fprintf(stderr, "Can't process DV frame #%d. Insufficient audio data or severe sync problem.\n", c->frames);
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
585
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
586 dv_inject_video(c, video, frame);
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
587 c->has_video = 1;
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
588 }
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
589 if (audio) {
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
590 reqasize = 4 * dv_audio_frame_size(c->sys, c->frames);
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
591 fsize = fifo_size(&c->audio_data, c->audio_data.rptr);
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
592 if (fsize + asize >= reqasize) {
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
593 if (fsize >= reqasize) {
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
594 fifo_read(&c->audio_data, &pcm[0], reqasize, &c->audio_data.rptr);
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
595 } else {
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
596 fifo_read(&c->audio_data, &pcm[0], fsize, &c->audio_data.rptr);
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
597 memcpy(&pcm[fsize], &audio[0], reqasize - fsize);
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
598 audio += reqasize - fsize;
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
599 asize -= reqasize - fsize;
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
600 }
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
601 dv_inject_audio(c, &pcm[0], frame);
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
602 c->has_audio = 1;
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
603 }
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
604
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
605 /* FIXME: we have to have more sensible approach than this one */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
606 if (fifo_size(&c->audio_data, c->audio_data.rptr) + asize >= AVCODEC_MAX_AUDIO_FRAME_SIZE)
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
607 fprintf(stderr, "Can't process DV frame #%d. Insufficient video data or severe sync problem.\n", c->frames);
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
608 fifo_write(&c->audio_data, audio, asize, &c->audio_data.wptr);
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
609 }
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
610 }
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
611
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
612 int dv_core_init(DVMuxContext *c, AVStream *streams[])
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
613 {
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
614 /* We have to sort out where audio and where video stream is */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
615 if (streams[0]->codec.codec_type == CODEC_TYPE_VIDEO &&
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
616 streams[1]->codec.codec_type == CODEC_TYPE_AUDIO) {
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
617 c->vst = 0;
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
618 c->ast = 1;
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
619 }
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
620 else if (streams[1]->codec.codec_type == CODEC_TYPE_VIDEO &&
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
621 streams[0]->codec.codec_type == CODEC_TYPE_AUDIO) {
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
622 c->vst = 1;
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
623 c->ast = 0;
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
624 } else
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
625 goto bail_out;
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
626
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
627 /* Some checks -- DV format is very picky about its incoming streams */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
628 if (streams[c->vst]->codec.codec_id != CODEC_ID_DVVIDEO ||
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
629 streams[c->ast]->codec.codec_id != CODEC_ID_PCM_S16LE)
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
630 goto bail_out;
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
631 if (streams[c->ast]->codec.sample_rate != 48000 ||
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
632 streams[c->ast]->codec.channels != 2)
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
633 goto bail_out;
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
634
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
635 if (streams[c->vst]->codec.frame_rate == 25 &&
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
636 streams[c->vst]->codec.frame_rate_base == 1) {
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
637 /* May be we have to pick sys for every frame */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
638 c->sys = &dv_profiles[1];
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
639 }
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
640 else if (streams[c->vst]->codec.frame_rate == 30000 &&
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
641 streams[c->vst]->codec.frame_rate_base == 1001) {
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
642 /* May be we have to pick sys for every frame */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
643 c->sys = &dv_profiles[0];
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
644 } else
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
645 goto bail_out;
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
646
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
647 /* Ok, everything seems to be in working order */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
648 c->frames = 0;
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
649 c->has_audio = c->has_video = 0;
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
650 c->start_time = time(NULL);
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
651 c->aspect = 0; /* 4:3 is the default */
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
652 if (streams[c->vst]->codec.aspect_ratio == 16.0 / 9.0)
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
653 c->aspect = 0x07;
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
654
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
655 if (fifo_init(&c->audio_data, AVCODEC_MAX_AUDIO_FRAME_SIZE) < 0)
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
656 goto bail_out;
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
657
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
658 dv_format_frame(c, &c->frame_buf[0]);
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
659
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
660 return 0;
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
661
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
662 bail_out:
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
663 return -1;
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
664 }
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
665
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
666 void dv_core_delete(DVMuxContext *c)
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
667 {
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
668 fifo_free(&c->audio_data);
184d22d04c84 * Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
diff changeset
669 }