10094
|
1 #include <stdio.h>
|
|
2 #include <stdlib.h>
|
|
3 #include <stdarg.h>
|
|
4 #include <assert.h>
|
|
5
|
|
6 #include "config.h"
|
|
7 #include "mp_msg.h"
|
|
8 #include "help_mp.h"
|
|
9
|
|
10 #include "vd_internal.h"
|
|
11
|
|
12 static vd_info_t info = {
|
|
13 "Theora/VP3",
|
|
14 "theora",
|
|
15 "David Kuehling",
|
|
16 "www.theora.org",
|
|
17 "Theora project's VP3 codec"
|
|
18 };
|
|
19
|
|
20 LIBVD_EXTERN(theora)
|
|
21
|
|
22 #include <theora/theora.h>
|
|
23
|
10658
|
24 #define THEORA_NUM_HEADER_PACKETS 3
|
|
25
|
10094
|
26 // to set/get/query special features/parameters
|
|
27 static int control(sh_video_t *sh,int cmd,void* arg,...){
|
14763
|
28 switch(cmd) {
|
|
29 case VDCTRL_QUERY_FORMAT:
|
|
30 if ((*((int*)arg)) == IMGFMT_YV12)
|
|
31 return CONTROL_TRUE;
|
|
32 return CONTROL_FALSE;
|
|
33 }
|
|
34
|
10094
|
35 return CONTROL_UNKNOWN;
|
|
36 }
|
|
37
|
|
38 typedef struct theora_struct_st {
|
|
39 theora_state st;
|
10658
|
40 theora_comment cc;
|
10094
|
41 theora_info inf;
|
|
42 } theora_struct_t;
|
|
43
|
|
44 /*
|
|
45 * init driver
|
|
46 */
|
|
47 static int init(sh_video_t *sh){
|
|
48 theora_struct_t *context = NULL;
|
|
49 int failed = 1;
|
|
50 int errorCode = 0;
|
|
51 ogg_packet op;
|
10658
|
52 int i;
|
10094
|
53
|
|
54 /* check whether video output format is supported */
|
|
55 switch(sh->codec->outfmt[sh->outfmtidx])
|
|
56 {
|
|
57 case IMGFMT_YV12: /* well, this should work... */ break;
|
|
58 default:
|
|
59 mp_msg (MSGT_DECVIDEO,MSGL_ERR,"Unsupported out_fmt: 0x%X\n",
|
|
60 sh->codec->outfmt[sh->outfmtidx]);
|
|
61 return 0;
|
|
62 }
|
|
63
|
|
64 /* this is not a loop, just a context, from which we can break on error */
|
|
65 do
|
|
66 {
|
18879
|
67 context = calloc (sizeof (theora_struct_t), 1);
|
10094
|
68 sh->context = context;
|
|
69 if (!context)
|
|
70 break;
|
10658
|
71
|
|
72 theora_info_init(&context->inf);
|
|
73 theora_comment_init(&context->cc);
|
10094
|
74
|
10658
|
75 /* Read all header packets, pass them to theora_decode_header. */
|
|
76 for (i = 0; i < THEORA_NUM_HEADER_PACKETS; i++)
|
|
77 {
|
|
78 op.bytes = ds_get_packet (sh->ds, &op.packet);
|
|
79 op.b_o_s = 1;
|
|
80 if ( (errorCode = theora_decode_header (&context->inf, &context->cc, &op)) )
|
|
81 {
|
|
82 mp_msg(MSGT_DECAUDIO, MSGL_ERR, "Broken Theora header; errorCode=%i!\n", errorCode);
|
|
83 break;
|
|
84 }
|
10094
|
85 }
|
10658
|
86 if (errorCode)
|
|
87 break;
|
10251
|
88
|
|
89 /* now init codec */
|
10094
|
90 errorCode = theora_decode_init (&context->st, &context->inf);
|
|
91 if (errorCode)
|
|
92 {
|
|
93 mp_msg(MSGT_DECVIDEO,MSGL_ERR,"Theora decode init failed: %i \n",
|
|
94 errorCode);
|
|
95 break;
|
|
96 }
|
|
97 failed = 0;
|
|
98 } while (0);
|
|
99
|
|
100 if (failed)
|
|
101 {
|
|
102 if (context)
|
|
103 {
|
|
104 free (context);
|
|
105 sh->context = NULL;
|
|
106 }
|
|
107 return 0;
|
|
108 }
|
|
109
|
12761
|
110 if(sh->aspect==0.0 && context->inf.aspect_denominator!=0)
|
|
111 {
|
14763
|
112 sh->aspect = (float)(context->inf.aspect_numerator * context->inf.frame_width)/
|
|
113 (context->inf.aspect_denominator * context->inf.frame_height);
|
12761
|
114 }
|
|
115
|
10094
|
116 mp_msg(MSGT_DECVIDEO,MSGL_V,"INFO: Theora video init ok!\n");
|
|
117
|
14763
|
118 return mpcodecs_config_vo (sh,context->inf.frame_width,context->inf.frame_height,IMGFMT_YV12);
|
10094
|
119 }
|
|
120
|
|
121 /*
|
|
122 * uninit driver
|
|
123 */
|
|
124 static void uninit(sh_video_t *sh)
|
|
125 {
|
|
126 theora_struct_t *context = (theora_struct_t *)sh->context;
|
|
127
|
|
128 if (context)
|
|
129 {
|
|
130 theora_clear (&context->st);
|
|
131 free (context);
|
|
132 }
|
|
133 }
|
|
134
|
|
135 /*
|
|
136 * decode frame
|
|
137 */
|
|
138 static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags)
|
|
139 {
|
|
140 theora_struct_t *context = (theora_struct_t *)sh->context;
|
|
141 int errorCode = 0;
|
|
142 ogg_packet op;
|
|
143 yuv_buffer yuv;
|
|
144 mp_image_t* mpi;
|
|
145
|
14642
|
146 memset (&op, 0, sizeof (op));
|
10094
|
147 op.bytes = len;
|
|
148 op.packet = data;
|
|
149 op.granulepos = -1;
|
|
150
|
|
151 errorCode = theora_decode_packetin (&context->st, &op);
|
|
152 if (errorCode)
|
|
153 {
|
|
154 mp_msg(MSGT_DECVIDEO,MSGL_ERR,"Theora decode packetin failed: %i \n",
|
|
155 errorCode);
|
|
156 return NULL;
|
|
157 }
|
|
158
|
|
159 errorCode = theora_decode_YUVout (&context->st, &yuv);
|
|
160 if (errorCode)
|
|
161 {
|
|
162 mp_msg(MSGT_DEMUX,MSGL_ERR,"Theora decode YUVout failed: %i \n",
|
|
163 errorCode);
|
|
164 return 0;
|
|
165 }
|
|
166
|
14781
|
167 mpi = mpcodecs_get_image(sh, MP_IMGTYPE_EXPORT, 0, yuv.y_width, yuv.y_height);
|
10094
|
168 if(!mpi) return NULL;
|
14781
|
169
|
|
170 mpi->planes[0]=yuv.y;
|
|
171 mpi->stride[0]=yuv.y_stride;
|
|
172 mpi->planes[1]=yuv.u;
|
|
173 mpi->stride[1]=yuv.uv_stride;
|
|
174 mpi->planes[2]=yuv.v;
|
|
175 mpi->stride[2]=yuv.uv_stride;
|
14763
|
176
|
10094
|
177 return mpi;
|
|
178 }
|