annotate libmpcodecs/vd_theora.c @ 34798:e3ceb73d4152

Fix A-V desync with skipframe and H.264. This will however cause desync when skipframe is used on PAFF H.264 content without correct-pts.
author reimar
date Sun, 06 May 2012 08:44:28 +0000
parents 1c7446e6c426
children 139f2b064ef9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
30421
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
1 /*
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
2 * This file is part of MPlayer.
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
3 *
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
4 * MPlayer is free software; you can redistribute it and/or modify
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
5 * it under the terms of the GNU General Public License as published by
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
6 * the Free Software Foundation; either version 2 of the License, or
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
7 * (at your option) any later version.
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
8 *
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
9 * MPlayer is distributed in the hope that it will be useful,
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
12 * GNU General Public License for more details.
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
13 *
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
14 * You should have received a copy of the GNU General Public License along
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
17 */
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
18
10094
5730f6098f98 theora video decoder, based on patch by David Kuehling <dvdkhlng@gmx.de>
arpi
parents:
diff changeset
19 #include <stdio.h>
5730f6098f98 theora video decoder, based on patch by David Kuehling <dvdkhlng@gmx.de>
arpi
parents:
diff changeset
20 #include <stdlib.h>
5730f6098f98 theora video decoder, based on patch by David Kuehling <dvdkhlng@gmx.de>
arpi
parents:
diff changeset
21 #include <stdarg.h>
5730f6098f98 theora video decoder, based on patch by David Kuehling <dvdkhlng@gmx.de>
arpi
parents:
diff changeset
22 #include <assert.h>
5730f6098f98 theora video decoder, based on patch by David Kuehling <dvdkhlng@gmx.de>
arpi
parents:
diff changeset
23
5730f6098f98 theora video decoder, based on patch by David Kuehling <dvdkhlng@gmx.de>
arpi
parents:
diff changeset
24 #include "config.h"
5730f6098f98 theora video decoder, based on patch by David Kuehling <dvdkhlng@gmx.de>
arpi
parents:
diff changeset
25 #include "mp_msg.h"
5730f6098f98 theora video decoder, based on patch by David Kuehling <dvdkhlng@gmx.de>
arpi
parents:
diff changeset
26 #include "help_mp.h"
5730f6098f98 theora video decoder, based on patch by David Kuehling <dvdkhlng@gmx.de>
arpi
parents:
diff changeset
27
5730f6098f98 theora video decoder, based on patch by David Kuehling <dvdkhlng@gmx.de>
arpi
parents:
diff changeset
28 #include "vd_internal.h"
5730f6098f98 theora video decoder, based on patch by David Kuehling <dvdkhlng@gmx.de>
arpi
parents:
diff changeset
29
30890
1c92dce71f3d add support for lavf style extradata in vd_theora
aurel
parents: 30543
diff changeset
30 #include "libavutil/intreadwrite.h"
1c92dce71f3d add support for lavf style extradata in vd_theora
aurel
parents: 30543
diff changeset
31
30504
cc27da5d7286 Mark all ad_info_t/vd_info_t structure declarations as const.
diego
parents: 30421
diff changeset
32 static const vd_info_t info = {
34496
1c7446e6c426 vd theora: cosmetics: K&R style, alignment
al
parents: 34493
diff changeset
33 "Theora/VP3",
1c7446e6c426 vd theora: cosmetics: K&R style, alignment
al
parents: 34493
diff changeset
34 "theora",
1c7446e6c426 vd theora: cosmetics: K&R style, alignment
al
parents: 34493
diff changeset
35 "David Kuehling",
1c7446e6c426 vd theora: cosmetics: K&R style, alignment
al
parents: 34493
diff changeset
36 "www.theora.org",
1c7446e6c426 vd theora: cosmetics: K&R style, alignment
al
parents: 34493
diff changeset
37 "Theora project's VP3 codec"
10094
5730f6098f98 theora video decoder, based on patch by David Kuehling <dvdkhlng@gmx.de>
arpi
parents:
diff changeset
38 };
5730f6098f98 theora video decoder, based on patch by David Kuehling <dvdkhlng@gmx.de>
arpi
parents:
diff changeset
39
5730f6098f98 theora video decoder, based on patch by David Kuehling <dvdkhlng@gmx.de>
arpi
parents:
diff changeset
40 LIBVD_EXTERN(theora)
5730f6098f98 theora video decoder, based on patch by David Kuehling <dvdkhlng@gmx.de>
arpi
parents:
diff changeset
41
34415
55ff5df09657 Port libtheora glue code to Theora 1.0 API.
diego
parents: 31188
diff changeset
42 #include <theora/theoradec.h>
10094
5730f6098f98 theora video decoder, based on patch by David Kuehling <dvdkhlng@gmx.de>
arpi
parents:
diff changeset
43
10658
c5e7b34bfc19 Theora-CVS update patch by Martin Drab <drab@kepler.fjfi.cvut.cz>
alex
parents: 10251
diff changeset
44 #define THEORA_NUM_HEADER_PACKETS 3
c5e7b34bfc19 Theora-CVS update patch by Martin Drab <drab@kepler.fjfi.cvut.cz>
alex
parents: 10251
diff changeset
45
30543
ee0b9c3bbf29 Add support for decoding 4:2:2 and 4:4:4 Theora files.
reimar
parents: 30527
diff changeset
46 typedef struct theora_struct_st {
34496
1c7446e6c426 vd theora: cosmetics: K&R style, alignment
al
parents: 34493
diff changeset
47 th_setup_info *tsi;
1c7446e6c426 vd theora: cosmetics: K&R style, alignment
al
parents: 34493
diff changeset
48 th_dec_ctx *tctx;
1c7446e6c426 vd theora: cosmetics: K&R style, alignment
al
parents: 34493
diff changeset
49 th_comment tc;
1c7446e6c426 vd theora: cosmetics: K&R style, alignment
al
parents: 34493
diff changeset
50 th_info ti;
34493
da31318562d9 vd_theora: Skip th_decode_ycbcr_out() for packets representing dropped frames.
diego
parents: 34415
diff changeset
51 th_ycbcr_buffer ycbcrbuf;
30543
ee0b9c3bbf29 Add support for decoding 4:2:2 and 4:4:4 Theora files.
reimar
parents: 30527
diff changeset
52 } theora_struct_t;
ee0b9c3bbf29 Add support for decoding 4:2:2 and 4:4:4 Theora files.
reimar
parents: 30527
diff changeset
53
ee0b9c3bbf29 Add support for decoding 4:2:2 and 4:4:4 Theora files.
reimar
parents: 30527
diff changeset
54 /** Convert Theora pixelformat to the corresponding IMGFMT_ */
34496
1c7446e6c426 vd theora: cosmetics: K&R style, alignment
al
parents: 34493
diff changeset
55 static uint32_t theora_pixelformat2imgfmt(th_pixel_fmt fmt)
1c7446e6c426 vd theora: cosmetics: K&R style, alignment
al
parents: 34493
diff changeset
56 {
1c7446e6c426 vd theora: cosmetics: K&R style, alignment
al
parents: 34493
diff changeset
57 switch (fmt) {
1c7446e6c426 vd theora: cosmetics: K&R style, alignment
al
parents: 34493
diff changeset
58 case TH_PF_420: return IMGFMT_YV12;
1c7446e6c426 vd theora: cosmetics: K&R style, alignment
al
parents: 34493
diff changeset
59 case TH_PF_422: return IMGFMT_422P;
1c7446e6c426 vd theora: cosmetics: K&R style, alignment
al
parents: 34493
diff changeset
60 case TH_PF_444: return IMGFMT_444P;
30543
ee0b9c3bbf29 Add support for decoding 4:2:2 and 4:4:4 Theora files.
reimar
parents: 30527
diff changeset
61 }
ee0b9c3bbf29 Add support for decoding 4:2:2 and 4:4:4 Theora files.
reimar
parents: 30527
diff changeset
62 return 0;
ee0b9c3bbf29 Add support for decoding 4:2:2 and 4:4:4 Theora files.
reimar
parents: 30527
diff changeset
63 }
ee0b9c3bbf29 Add support for decoding 4:2:2 and 4:4:4 Theora files.
reimar
parents: 30527
diff changeset
64
10094
5730f6098f98 theora video decoder, based on patch by David Kuehling <dvdkhlng@gmx.de>
arpi
parents:
diff changeset
65 // to set/get/query special features/parameters
34496
1c7446e6c426 vd theora: cosmetics: K&R style, alignment
al
parents: 34493
diff changeset
66 static int control(sh_video_t *sh, int cmd, void *arg, ...)
1c7446e6c426 vd theora: cosmetics: K&R style, alignment
al
parents: 34493
diff changeset
67 {
30543
ee0b9c3bbf29 Add support for decoding 4:2:2 and 4:4:4 Theora files.
reimar
parents: 30527
diff changeset
68 theora_struct_t *context = sh->context;
34496
1c7446e6c426 vd theora: cosmetics: K&R style, alignment
al
parents: 34493
diff changeset
69 switch (cmd) {
14763
2c4e30f37773 Theora fixes:
henry
parents: 14642
diff changeset
70 case VDCTRL_QUERY_FORMAT:
34496
1c7446e6c426 vd theora: cosmetics: K&R style, alignment
al
parents: 34493
diff changeset
71 if (*(int *)arg == theora_pixelformat2imgfmt(context->ti.pixel_fmt))
1c7446e6c426 vd theora: cosmetics: K&R style, alignment
al
parents: 34493
diff changeset
72 return CONTROL_TRUE;
1c7446e6c426 vd theora: cosmetics: K&R style, alignment
al
parents: 34493
diff changeset
73 return CONTROL_FALSE;
14763
2c4e30f37773 Theora fixes:
henry
parents: 14642
diff changeset
74 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 21499
diff changeset
75
10094
5730f6098f98 theora video decoder, based on patch by David Kuehling <dvdkhlng@gmx.de>
arpi
parents:
diff changeset
76 return CONTROL_UNKNOWN;
5730f6098f98 theora video decoder, based on patch by David Kuehling <dvdkhlng@gmx.de>
arpi
parents:
diff changeset
77 }
5730f6098f98 theora video decoder, based on patch by David Kuehling <dvdkhlng@gmx.de>
arpi
parents:
diff changeset
78
5730f6098f98 theora video decoder, based on patch by David Kuehling <dvdkhlng@gmx.de>
arpi
parents:
diff changeset
79 /*
5730f6098f98 theora video decoder, based on patch by David Kuehling <dvdkhlng@gmx.de>
arpi
parents:
diff changeset
80 * init driver
5730f6098f98 theora video decoder, based on patch by David Kuehling <dvdkhlng@gmx.de>
arpi
parents:
diff changeset
81 */
34496
1c7446e6c426 vd theora: cosmetics: K&R style, alignment
al
parents: 34493
diff changeset
82 static int init(sh_video_t *sh)
1c7446e6c426 vd theora: cosmetics: K&R style, alignment
al
parents: 34493
diff changeset
83 {
10094
5730f6098f98 theora video decoder, based on patch by David Kuehling <dvdkhlng@gmx.de>
arpi
parents:
diff changeset
84 theora_struct_t *context = NULL;
34496
1c7446e6c426 vd theora: cosmetics: K&R style, alignment
al
parents: 34493
diff changeset
85 uint8_t *extradata = (uint8_t *)(sh->bih + 1);
1c7446e6c426 vd theora: cosmetics: K&R style, alignment
al
parents: 34493
diff changeset
86 int extradata_size = sh->bih->biSize - sizeof(*sh->bih);
1c7446e6c426 vd theora: cosmetics: K&R style, alignment
al
parents: 34493
diff changeset
87 int errorCode = 0;
10094
5730f6098f98 theora video decoder, based on patch by David Kuehling <dvdkhlng@gmx.de>
arpi
parents:
diff changeset
88 ogg_packet op;
10658
c5e7b34bfc19 Theora-CVS update patch by Martin Drab <drab@kepler.fjfi.cvut.cz>
alex
parents: 10251
diff changeset
89 int i;
10094
5730f6098f98 theora video decoder, based on patch by David Kuehling <dvdkhlng@gmx.de>
arpi
parents:
diff changeset
90
34496
1c7446e6c426 vd theora: cosmetics: K&R style, alignment
al
parents: 34493
diff changeset
91 context = calloc(sizeof(theora_struct_t), 1);
30527
058d4fc12058 Reindent
reimar
parents: 30526
diff changeset
92 sh->context = context;
058d4fc12058 Reindent
reimar
parents: 30526
diff changeset
93 if (!context)
058d4fc12058 Reindent
reimar
parents: 30526
diff changeset
94 goto err_out;
10658
c5e7b34bfc19 Theora-CVS update patch by Martin Drab <drab@kepler.fjfi.cvut.cz>
alex
parents: 10251
diff changeset
95
34415
55ff5df09657 Port libtheora glue code to Theora 1.0 API.
diego
parents: 31188
diff changeset
96 th_info_init(&context->ti);
55ff5df09657 Port libtheora glue code to Theora 1.0 API.
diego
parents: 31188
diff changeset
97 th_comment_init(&context->tc);
55ff5df09657 Port libtheora glue code to Theora 1.0 API.
diego
parents: 31188
diff changeset
98 context->tsi = NULL;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 21499
diff changeset
99
30527
058d4fc12058 Reindent
reimar
parents: 30526
diff changeset
100 /* Read all header packets, pass them to theora_decode_header. */
34496
1c7446e6c426 vd theora: cosmetics: K&R style, alignment
al
parents: 34493
diff changeset
101 for (i = 0; i < THEORA_NUM_HEADER_PACKETS; i++) {
30890
1c92dce71f3d add support for lavf style extradata in vd_theora
aurel
parents: 30543
diff changeset
102 if (extradata_size > 2) {
1c92dce71f3d add support for lavf style extradata in vd_theora
aurel
parents: 30543
diff changeset
103 op.bytes = AV_RB16(extradata);
1c92dce71f3d add support for lavf style extradata in vd_theora
aurel
parents: 30543
diff changeset
104 op.packet = extradata + 2;
1c92dce71f3d add support for lavf style extradata in vd_theora
aurel
parents: 30543
diff changeset
105 op.b_o_s = 1;
1c92dce71f3d add support for lavf style extradata in vd_theora
aurel
parents: 30543
diff changeset
106 if (extradata_size < op.bytes + 2) {
31188
aff74c63b86d Use MSGT_DECVIDEO in a video decoder.
cehoyos
parents: 31149
diff changeset
107 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "Theora header too small\n");
30890
1c92dce71f3d add support for lavf style extradata in vd_theora
aurel
parents: 30543
diff changeset
108 goto err_out;
1c92dce71f3d add support for lavf style extradata in vd_theora
aurel
parents: 30543
diff changeset
109 }
1c92dce71f3d add support for lavf style extradata in vd_theora
aurel
parents: 30543
diff changeset
110 extradata += op.bytes + 2;
1c92dce71f3d add support for lavf style extradata in vd_theora
aurel
parents: 30543
diff changeset
111 extradata_size -= op.bytes + 2;
1c92dce71f3d add support for lavf style extradata in vd_theora
aurel
parents: 30543
diff changeset
112 } else {
34496
1c7446e6c426 vd theora: cosmetics: K&R style, alignment
al
parents: 34493
diff changeset
113 op.bytes = ds_get_packet(sh->ds, &op.packet);
30891
fdcf76890a16 cosmetics: indentation
aurel
parents: 30890
diff changeset
114 op.b_o_s = 1;
30890
1c92dce71f3d add support for lavf style extradata in vd_theora
aurel
parents: 30543
diff changeset
115 }
1c92dce71f3d add support for lavf style extradata in vd_theora
aurel
parents: 30543
diff changeset
116
34496
1c7446e6c426 vd theora: cosmetics: K&R style, alignment
al
parents: 34493
diff changeset
117 if ((errorCode = th_decode_headerin(&context->ti, &context->tc, &context->tsi, &op)) < 0) {
31188
aff74c63b86d Use MSGT_DECVIDEO in a video decoder.
cehoyos
parents: 31149
diff changeset
118 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "Broken Theora header; errorCode=%i!\n", errorCode);
30526
68e260df472b Just use goto instead of reimplementing it badly with a do { } while (0) and
reimar
parents: 30525
diff changeset
119 goto err_out;
30527
058d4fc12058 Reindent
reimar
parents: 30526
diff changeset
120 }
058d4fc12058 Reindent
reimar
parents: 30526
diff changeset
121 }
10251
95dc2037fb27 just updated vd_theora.c to decode the additional header packets,
arpi
parents: 10094
diff changeset
122
30527
058d4fc12058 Reindent
reimar
parents: 30526
diff changeset
123 /* now init codec */
34496
1c7446e6c426 vd theora: cosmetics: K&R style, alignment
al
parents: 34493
diff changeset
124 context->tctx = th_decode_alloc(&context->ti, context->tsi);
1c7446e6c426 vd theora: cosmetics: K&R style, alignment
al
parents: 34493
diff changeset
125 if (!context->tctx) {
1c7446e6c426 vd theora: cosmetics: K&R style, alignment
al
parents: 34493
diff changeset
126 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "Theora decode init failed\n");
30527
058d4fc12058 Reindent
reimar
parents: 30526
diff changeset
127 goto err_out;
058d4fc12058 Reindent
reimar
parents: 30526
diff changeset
128 }
34415
55ff5df09657 Port libtheora glue code to Theora 1.0 API.
diego
parents: 31188
diff changeset
129 /* free memory used for decoder setup information */
55ff5df09657 Port libtheora glue code to Theora 1.0 API.
diego
parents: 31188
diff changeset
130 th_setup_free(context->tsi);
10094
5730f6098f98 theora video decoder, based on patch by David Kuehling <dvdkhlng@gmx.de>
arpi
parents:
diff changeset
131
34496
1c7446e6c426 vd theora: cosmetics: K&R style, alignment
al
parents: 34493
diff changeset
132 if (sh->aspect == 0.0 && context->ti.aspect_denominator != 0) {
1c7446e6c426 vd theora: cosmetics: K&R style, alignment
al
parents: 34493
diff changeset
133 sh->aspect = ((double)context->ti.aspect_numerator * context->ti.frame_width) /
1c7446e6c426 vd theora: cosmetics: K&R style, alignment
al
parents: 34493
diff changeset
134 ((double)context->ti.aspect_denominator * context->ti.frame_height);
12761
236b49c548a5 Use aspect ratio from Theora context. Patch by j at v2v dot cc
mosu
parents: 10658
diff changeset
135 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 21499
diff changeset
136
34496
1c7446e6c426 vd theora: cosmetics: K&R style, alignment
al
parents: 34493
diff changeset
137 mp_msg(MSGT_DECVIDEO, MSGL_V, "INFO: Theora video init ok!\n");
1c7446e6c426 vd theora: cosmetics: K&R style, alignment
al
parents: 34493
diff changeset
138 mp_msg(MSGT_DECVIDEO, MSGL_INFO, "Frame %dx%d, Picture %dx%d, Offset [%d,%d]\n", context->ti.frame_width, context->ti.frame_height, context->ti.pic_width, context->ti.pic_height, context->ti.pic_x, context->ti.pic_y);
10094
5730f6098f98 theora video decoder, based on patch by David Kuehling <dvdkhlng@gmx.de>
arpi
parents:
diff changeset
139
34496
1c7446e6c426 vd theora: cosmetics: K&R style, alignment
al
parents: 34493
diff changeset
140 return mpcodecs_config_vo(sh, context->ti.frame_width, context->ti.frame_height, theora_pixelformat2imgfmt(context->ti.pixel_fmt));
30526
68e260df472b Just use goto instead of reimplementing it badly with a do { } while (0) and
reimar
parents: 30525
diff changeset
141
68e260df472b Just use goto instead of reimplementing it badly with a do { } while (0) and
reimar
parents: 30525
diff changeset
142 err_out:
68e260df472b Just use goto instead of reimplementing it badly with a do { } while (0) and
reimar
parents: 30525
diff changeset
143 free(context);
68e260df472b Just use goto instead of reimplementing it badly with a do { } while (0) and
reimar
parents: 30525
diff changeset
144 sh->context = NULL;
68e260df472b Just use goto instead of reimplementing it badly with a do { } while (0) and
reimar
parents: 30525
diff changeset
145 return 0;
10094
5730f6098f98 theora video decoder, based on patch by David Kuehling <dvdkhlng@gmx.de>
arpi
parents:
diff changeset
146 }
5730f6098f98 theora video decoder, based on patch by David Kuehling <dvdkhlng@gmx.de>
arpi
parents:
diff changeset
147
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 21499
diff changeset
148 /*
10094
5730f6098f98 theora video decoder, based on patch by David Kuehling <dvdkhlng@gmx.de>
arpi
parents:
diff changeset
149 * uninit driver
5730f6098f98 theora video decoder, based on patch by David Kuehling <dvdkhlng@gmx.de>
arpi
parents:
diff changeset
150 */
5730f6098f98 theora video decoder, based on patch by David Kuehling <dvdkhlng@gmx.de>
arpi
parents:
diff changeset
151 static void uninit(sh_video_t *sh)
5730f6098f98 theora video decoder, based on patch by David Kuehling <dvdkhlng@gmx.de>
arpi
parents:
diff changeset
152 {
34496
1c7446e6c426 vd theora: cosmetics: K&R style, alignment
al
parents: 34493
diff changeset
153 theora_struct_t *context = sh->context;
10094
5730f6098f98 theora video decoder, based on patch by David Kuehling <dvdkhlng@gmx.de>
arpi
parents:
diff changeset
154
34496
1c7446e6c426 vd theora: cosmetics: K&R style, alignment
al
parents: 34493
diff changeset
155 if (context) {
1c7446e6c426 vd theora: cosmetics: K&R style, alignment
al
parents: 34493
diff changeset
156 th_info_clear(&context->ti);
1c7446e6c426 vd theora: cosmetics: K&R style, alignment
al
parents: 34493
diff changeset
157 th_comment_clear(&context->tc);
1c7446e6c426 vd theora: cosmetics: K&R style, alignment
al
parents: 34493
diff changeset
158 th_decode_free(context->tctx);
1c7446e6c426 vd theora: cosmetics: K&R style, alignment
al
parents: 34493
diff changeset
159 free(context);
1c7446e6c426 vd theora: cosmetics: K&R style, alignment
al
parents: 34493
diff changeset
160 }
10094
5730f6098f98 theora video decoder, based on patch by David Kuehling <dvdkhlng@gmx.de>
arpi
parents:
diff changeset
161 }
5730f6098f98 theora video decoder, based on patch by David Kuehling <dvdkhlng@gmx.de>
arpi
parents:
diff changeset
162
5730f6098f98 theora video decoder, based on patch by David Kuehling <dvdkhlng@gmx.de>
arpi
parents:
diff changeset
163 /*
5730f6098f98 theora video decoder, based on patch by David Kuehling <dvdkhlng@gmx.de>
arpi
parents:
diff changeset
164 * decode frame
5730f6098f98 theora video decoder, based on patch by David Kuehling <dvdkhlng@gmx.de>
arpi
parents:
diff changeset
165 */
34496
1c7446e6c426 vd theora: cosmetics: K&R style, alignment
al
parents: 34493
diff changeset
166 static mp_image_t *decode(sh_video_t *sh, void *data, int len, int flags)
10094
5730f6098f98 theora video decoder, based on patch by David Kuehling <dvdkhlng@gmx.de>
arpi
parents:
diff changeset
167 {
34496
1c7446e6c426 vd theora: cosmetics: K&R style, alignment
al
parents: 34493
diff changeset
168 theora_struct_t *context = sh->context;
1c7446e6c426 vd theora: cosmetics: K&R style, alignment
al
parents: 34493
diff changeset
169 int errorCode = 0;
1c7446e6c426 vd theora: cosmetics: K&R style, alignment
al
parents: 34493
diff changeset
170 ogg_packet op;
1c7446e6c426 vd theora: cosmetics: K&R style, alignment
al
parents: 34493
diff changeset
171 mp_image_t *mpi;
10094
5730f6098f98 theora video decoder, based on patch by David Kuehling <dvdkhlng@gmx.de>
arpi
parents:
diff changeset
172
34496
1c7446e6c426 vd theora: cosmetics: K&R style, alignment
al
parents: 34493
diff changeset
173 // no delayed frames
1c7446e6c426 vd theora: cosmetics: K&R style, alignment
al
parents: 34493
diff changeset
174 if (!data || !len)
1c7446e6c426 vd theora: cosmetics: K&R style, alignment
al
parents: 34493
diff changeset
175 return NULL;
31149
8b1a6a6cda36 Avoid decoding of 0-size packets. This also fixes that the main loop believes
reimar
parents: 31134
diff changeset
176
34496
1c7446e6c426 vd theora: cosmetics: K&R style, alignment
al
parents: 34493
diff changeset
177 memset(&op, 0, sizeof(op));
1c7446e6c426 vd theora: cosmetics: K&R style, alignment
al
parents: 34493
diff changeset
178 op.bytes = len;
1c7446e6c426 vd theora: cosmetics: K&R style, alignment
al
parents: 34493
diff changeset
179 op.packet = data;
1c7446e6c426 vd theora: cosmetics: K&R style, alignment
al
parents: 34493
diff changeset
180 op.granulepos = -1;
10094
5730f6098f98 theora video decoder, based on patch by David Kuehling <dvdkhlng@gmx.de>
arpi
parents:
diff changeset
181
34496
1c7446e6c426 vd theora: cosmetics: K&R style, alignment
al
parents: 34493
diff changeset
182 errorCode = th_decode_packetin(context->tctx, &op, NULL);
1c7446e6c426 vd theora: cosmetics: K&R style, alignment
al
parents: 34493
diff changeset
183 if (errorCode < 0) {
1c7446e6c426 vd theora: cosmetics: K&R style, alignment
al
parents: 34493
diff changeset
184 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "Theora decode packetin failed: %i \n",
1c7446e6c426 vd theora: cosmetics: K&R style, alignment
al
parents: 34493
diff changeset
185 errorCode);
1c7446e6c426 vd theora: cosmetics: K&R style, alignment
al
parents: 34493
diff changeset
186 return NULL;
1c7446e6c426 vd theora: cosmetics: K&R style, alignment
al
parents: 34493
diff changeset
187 }
10094
5730f6098f98 theora video decoder, based on patch by David Kuehling <dvdkhlng@gmx.de>
arpi
parents:
diff changeset
188
34493
da31318562d9 vd_theora: Skip th_decode_ycbcr_out() for packets representing dropped frames.
diego
parents: 34415
diff changeset
189 if (errorCode != TH_DUPFRAME) {
da31318562d9 vd_theora: Skip th_decode_ycbcr_out() for packets representing dropped frames.
diego
parents: 34415
diff changeset
190 errorCode = th_decode_ycbcr_out(context->tctx, context->ycbcrbuf);
da31318562d9 vd_theora: Skip th_decode_ycbcr_out() for packets representing dropped frames.
diego
parents: 34415
diff changeset
191 if (errorCode != 0) {
da31318562d9 vd_theora: Skip th_decode_ycbcr_out() for packets representing dropped frames.
diego
parents: 34415
diff changeset
192 mp_msg(MSGT_DECVIDEO, MSGL_ERR,
da31318562d9 vd_theora: Skip th_decode_ycbcr_out() for packets representing dropped frames.
diego
parents: 34415
diff changeset
193 "Theora decode YUVout failed: %i \n", errorCode);
da31318562d9 vd_theora: Skip th_decode_ycbcr_out() for packets representing dropped frames.
diego
parents: 34415
diff changeset
194 return NULL;
da31318562d9 vd_theora: Skip th_decode_ycbcr_out() for packets representing dropped frames.
diego
parents: 34415
diff changeset
195 }
da31318562d9 vd_theora: Skip th_decode_ycbcr_out() for packets representing dropped frames.
diego
parents: 34415
diff changeset
196 }
10094
5730f6098f98 theora video decoder, based on patch by David Kuehling <dvdkhlng@gmx.de>
arpi
parents:
diff changeset
197
34493
da31318562d9 vd_theora: Skip th_decode_ycbcr_out() for packets representing dropped frames.
diego
parents: 34415
diff changeset
198 mpi = mpcodecs_get_image(sh, MP_IMGTYPE_EXPORT, 0,
da31318562d9 vd_theora: Skip th_decode_ycbcr_out() for packets representing dropped frames.
diego
parents: 34415
diff changeset
199 context->ycbcrbuf[0].width,
da31318562d9 vd_theora: Skip th_decode_ycbcr_out() for packets representing dropped frames.
diego
parents: 34415
diff changeset
200 context->ycbcrbuf[0].height);
34496
1c7446e6c426 vd theora: cosmetics: K&R style, alignment
al
parents: 34493
diff changeset
201 if (!mpi)
1c7446e6c426 vd theora: cosmetics: K&R style, alignment
al
parents: 34493
diff changeset
202 return NULL;
14781
28e19750b448 revert the flip part of vd_theora fix
henry
parents: 14763
diff changeset
203
34493
da31318562d9 vd_theora: Skip th_decode_ycbcr_out() for packets representing dropped frames.
diego
parents: 34415
diff changeset
204 mpi->planes[0] = context->ycbcrbuf[0].data;
da31318562d9 vd_theora: Skip th_decode_ycbcr_out() for packets representing dropped frames.
diego
parents: 34415
diff changeset
205 mpi->stride[0] = context->ycbcrbuf[0].stride;
da31318562d9 vd_theora: Skip th_decode_ycbcr_out() for packets representing dropped frames.
diego
parents: 34415
diff changeset
206 mpi->planes[1] = context->ycbcrbuf[1].data;
da31318562d9 vd_theora: Skip th_decode_ycbcr_out() for packets representing dropped frames.
diego
parents: 34415
diff changeset
207 mpi->stride[1] = context->ycbcrbuf[1].stride;
da31318562d9 vd_theora: Skip th_decode_ycbcr_out() for packets representing dropped frames.
diego
parents: 34415
diff changeset
208 mpi->planes[2] = context->ycbcrbuf[2].data;
da31318562d9 vd_theora: Skip th_decode_ycbcr_out() for packets representing dropped frames.
diego
parents: 34415
diff changeset
209 mpi->stride[2] = context->ycbcrbuf[2].stride;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 21499
diff changeset
210
10094
5730f6098f98 theora video decoder, based on patch by David Kuehling <dvdkhlng@gmx.de>
arpi
parents:
diff changeset
211 return mpi;
5730f6098f98 theora video decoder, based on patch by David Kuehling <dvdkhlng@gmx.de>
arpi
parents:
diff changeset
212 }