comparison libmpcodecs/vd_theora.c @ 34496:1c7446e6c426

vd theora: cosmetics: K&R style, alignment Additionally one INFO level output message was slightly changed. patch by Giorgio Vazzana, mywing81 gmail com
author al
date Sat, 21 Jan 2012 17:43:06 +0000
parents da31318562d9
children 139f2b064ef9
comparison
equal deleted inserted replaced
34495:a5f7e1b5b0ce 34496:1c7446e6c426
28 #include "vd_internal.h" 28 #include "vd_internal.h"
29 29
30 #include "libavutil/intreadwrite.h" 30 #include "libavutil/intreadwrite.h"
31 31
32 static const vd_info_t info = { 32 static const vd_info_t info = {
33 "Theora/VP3", 33 "Theora/VP3",
34 "theora", 34 "theora",
35 "David Kuehling", 35 "David Kuehling",
36 "www.theora.org", 36 "www.theora.org",
37 "Theora project's VP3 codec" 37 "Theora project's VP3 codec"
38 }; 38 };
39 39
40 LIBVD_EXTERN(theora) 40 LIBVD_EXTERN(theora)
41 41
42 #include <theora/theoradec.h> 42 #include <theora/theoradec.h>
43 43
44 #define THEORA_NUM_HEADER_PACKETS 3 44 #define THEORA_NUM_HEADER_PACKETS 3
45 45
46 typedef struct theora_struct_st { 46 typedef struct theora_struct_st {
47 th_setup_info *tsi; 47 th_setup_info *tsi;
48 th_dec_ctx *tctx; 48 th_dec_ctx *tctx;
49 th_comment tc; 49 th_comment tc;
50 th_info ti; 50 th_info ti;
51 th_ycbcr_buffer ycbcrbuf; 51 th_ycbcr_buffer ycbcrbuf;
52 } theora_struct_t; 52 } theora_struct_t;
53 53
54 /** Convert Theora pixelformat to the corresponding IMGFMT_ */ 54 /** Convert Theora pixelformat to the corresponding IMGFMT_ */
55 static uint32_t theora_pixelformat2imgfmt(th_pixel_fmt fmt){ 55 static uint32_t theora_pixelformat2imgfmt(th_pixel_fmt fmt)
56 switch(fmt) { 56 {
57 case TH_PF_420: return IMGFMT_YV12; 57 switch (fmt) {
58 case TH_PF_422: return IMGFMT_422P; 58 case TH_PF_420: return IMGFMT_YV12;
59 case TH_PF_444: return IMGFMT_444P; 59 case TH_PF_422: return IMGFMT_422P;
60 case TH_PF_444: return IMGFMT_444P;
60 } 61 }
61 return 0; 62 return 0;
62 } 63 }
63 64
64 // to set/get/query special features/parameters 65 // to set/get/query special features/parameters
65 static int control(sh_video_t *sh,int cmd,void* arg,...){ 66 static int control(sh_video_t *sh, int cmd, void *arg, ...)
67 {
66 theora_struct_t *context = sh->context; 68 theora_struct_t *context = sh->context;
67 switch(cmd) { 69 switch (cmd) {
68 case VDCTRL_QUERY_FORMAT: 70 case VDCTRL_QUERY_FORMAT:
69 if (*(int*)arg == theora_pixelformat2imgfmt(context->ti.pixel_fmt)) 71 if (*(int *)arg == theora_pixelformat2imgfmt(context->ti.pixel_fmt))
70 return CONTROL_TRUE; 72 return CONTROL_TRUE;
71 return CONTROL_FALSE; 73 return CONTROL_FALSE;
72 } 74 }
73 75
74 return CONTROL_UNKNOWN; 76 return CONTROL_UNKNOWN;
75 } 77 }
76 78
77 /* 79 /*
78 * init driver 80 * init driver
79 */ 81 */
80 static int init(sh_video_t *sh){ 82 static int init(sh_video_t *sh)
83 {
81 theora_struct_t *context = NULL; 84 theora_struct_t *context = NULL;
82 uint8_t *extradata = (uint8_t *)(sh->bih + 1); 85 uint8_t *extradata = (uint8_t *)(sh->bih + 1);
83 int extradata_size = sh->bih->biSize - sizeof(*sh->bih); 86 int extradata_size = sh->bih->biSize - sizeof(*sh->bih);
84 int errorCode = 0; 87 int errorCode = 0;
85 ogg_packet op; 88 ogg_packet op;
86 int i; 89 int i;
87 90
88 context = calloc (sizeof (theora_struct_t), 1); 91 context = calloc(sizeof(theora_struct_t), 1);
89 sh->context = context; 92 sh->context = context;
90 if (!context) 93 if (!context)
91 goto err_out; 94 goto err_out;
92 95
93 th_info_init(&context->ti); 96 th_info_init(&context->ti);
94 th_comment_init(&context->tc); 97 th_comment_init(&context->tc);
95 context->tsi = NULL; 98 context->tsi = NULL;
96 99
97 /* Read all header packets, pass them to theora_decode_header. */ 100 /* Read all header packets, pass them to theora_decode_header. */
98 for (i = 0; i < THEORA_NUM_HEADER_PACKETS; i++) 101 for (i = 0; i < THEORA_NUM_HEADER_PACKETS; i++) {
99 {
100 if (extradata_size > 2) { 102 if (extradata_size > 2) {
101 op.bytes = AV_RB16(extradata); 103 op.bytes = AV_RB16(extradata);
102 op.packet = extradata + 2; 104 op.packet = extradata + 2;
103 op.b_o_s = 1; 105 op.b_o_s = 1;
104 if (extradata_size < op.bytes + 2) { 106 if (extradata_size < op.bytes + 2) {
106 goto err_out; 108 goto err_out;
107 } 109 }
108 extradata += op.bytes + 2; 110 extradata += op.bytes + 2;
109 extradata_size -= op.bytes + 2; 111 extradata_size -= op.bytes + 2;
110 } else { 112 } else {
111 op.bytes = ds_get_packet (sh->ds, &op.packet); 113 op.bytes = ds_get_packet(sh->ds, &op.packet);
112 op.b_o_s = 1; 114 op.b_o_s = 1;
113 } 115 }
114 116
115 if ( (errorCode = th_decode_headerin (&context->ti, &context->tc, &context->tsi, &op)) < 0) 117 if ((errorCode = th_decode_headerin(&context->ti, &context->tc, &context->tsi, &op)) < 0) {
116 {
117 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "Broken Theora header; errorCode=%i!\n", errorCode); 118 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "Broken Theora header; errorCode=%i!\n", errorCode);
118 goto err_out; 119 goto err_out;
119 } 120 }
120 } 121 }
121 122
122 /* now init codec */ 123 /* now init codec */
123 context->tctx = th_decode_alloc (&context->ti, context->tsi); 124 context->tctx = th_decode_alloc(&context->ti, context->tsi);
124 if (!context->tctx) 125 if (!context->tctx) {
125 { 126 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "Theora decode init failed\n");
126 mp_msg(MSGT_DECVIDEO,MSGL_ERR,"Theora decode init failed\n");
127 goto err_out; 127 goto err_out;
128 } 128 }
129 /* free memory used for decoder setup information */ 129 /* free memory used for decoder setup information */
130 th_setup_free(context->tsi); 130 th_setup_free(context->tsi);
131 131
132 if(sh->aspect==0.0 && context->ti.aspect_denominator!=0) 132 if (sh->aspect == 0.0 && context->ti.aspect_denominator != 0) {
133 { 133 sh->aspect = ((double)context->ti.aspect_numerator * context->ti.frame_width) /
134 sh->aspect = ((double)context->ti.aspect_numerator * context->ti.frame_width)/ 134 ((double)context->ti.aspect_denominator * context->ti.frame_height);
135 ((double)context->ti.aspect_denominator * context->ti.frame_height); 135 }
136 } 136
137 137 mp_msg(MSGT_DECVIDEO, MSGL_V, "INFO: Theora video init ok!\n");
138 mp_msg(MSGT_DECVIDEO,MSGL_V,"INFO: Theora video init ok!\n"); 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);
139 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); 139
140 140 return mpcodecs_config_vo(sh, context->ti.frame_width, context->ti.frame_height, theora_pixelformat2imgfmt(context->ti.pixel_fmt));
141 return mpcodecs_config_vo (sh,context->ti.frame_width,context->ti.frame_height,theora_pixelformat2imgfmt(context->ti.pixel_fmt));
142 141
143 err_out: 142 err_out:
144 free(context); 143 free(context);
145 sh->context = NULL; 144 sh->context = NULL;
146 return 0; 145 return 0;
149 /* 148 /*
150 * uninit driver 149 * uninit driver
151 */ 150 */
152 static void uninit(sh_video_t *sh) 151 static void uninit(sh_video_t *sh)
153 { 152 {
154 theora_struct_t *context = sh->context; 153 theora_struct_t *context = sh->context;
155 154
156 if (context) 155 if (context) {
157 { 156 th_info_clear(&context->ti);
158 th_info_clear(&context->ti); 157 th_comment_clear(&context->tc);
159 th_comment_clear(&context->tc); 158 th_decode_free(context->tctx);
160 th_decode_free (context->tctx); 159 free(context);
161 free (context); 160 }
162 }
163 } 161 }
164 162
165 /* 163 /*
166 * decode frame 164 * decode frame
167 */ 165 */
168 static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags) 166 static mp_image_t *decode(sh_video_t *sh, void *data, int len, int flags)
169 { 167 {
170 theora_struct_t *context = sh->context; 168 theora_struct_t *context = sh->context;
171 int errorCode = 0; 169 int errorCode = 0;
172 ogg_packet op; 170 ogg_packet op;
173 mp_image_t* mpi; 171 mp_image_t *mpi;
174 172
175 // no delayed frames 173 // no delayed frames
176 if (!data || !len) 174 if (!data || !len)
177 return NULL; 175 return NULL;
178 176
179 memset (&op, 0, sizeof (op)); 177 memset(&op, 0, sizeof(op));
180 op.bytes = len; 178 op.bytes = len;
181 op.packet = data; 179 op.packet = data;
182 op.granulepos = -1; 180 op.granulepos = -1;
183 181
184 errorCode = th_decode_packetin (context->tctx, &op, NULL); 182 errorCode = th_decode_packetin(context->tctx, &op, NULL);
185 if (errorCode < 0) 183 if (errorCode < 0) {
186 { 184 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "Theora decode packetin failed: %i \n",
187 mp_msg(MSGT_DECVIDEO,MSGL_ERR,"Theora decode packetin failed: %i \n", 185 errorCode);
188 errorCode); 186 return NULL;
189 return NULL; 187 }
190 }
191 188
192 if (errorCode != TH_DUPFRAME) { 189 if (errorCode != TH_DUPFRAME) {
193 errorCode = th_decode_ycbcr_out(context->tctx, context->ycbcrbuf); 190 errorCode = th_decode_ycbcr_out(context->tctx, context->ycbcrbuf);
194 if (errorCode != 0) { 191 if (errorCode != 0) {
195 mp_msg(MSGT_DECVIDEO, MSGL_ERR, 192 mp_msg(MSGT_DECVIDEO, MSGL_ERR,
199 } 196 }
200 197
201 mpi = mpcodecs_get_image(sh, MP_IMGTYPE_EXPORT, 0, 198 mpi = mpcodecs_get_image(sh, MP_IMGTYPE_EXPORT, 0,
202 context->ycbcrbuf[0].width, 199 context->ycbcrbuf[0].width,
203 context->ycbcrbuf[0].height); 200 context->ycbcrbuf[0].height);
204 if(!mpi) return NULL; 201 if (!mpi)
202 return NULL;
205 203
206 mpi->planes[0] = context->ycbcrbuf[0].data; 204 mpi->planes[0] = context->ycbcrbuf[0].data;
207 mpi->stride[0] = context->ycbcrbuf[0].stride; 205 mpi->stride[0] = context->ycbcrbuf[0].stride;
208 mpi->planes[1] = context->ycbcrbuf[1].data; 206 mpi->planes[1] = context->ycbcrbuf[1].data;
209 mpi->stride[1] = context->ycbcrbuf[1].stride; 207 mpi->stride[1] = context->ycbcrbuf[1].stride;