]> git.sesse.net Git - vlc/blob - modules/codec/theora.c
* modules/codec/theora.c, modules/stream_out/transcode.c: theora encoding fixes.
[vlc] / modules / codec / theora.c
1 /*****************************************************************************
2  * theora.c: theora decoder module making use of libtheora.
3  *****************************************************************************
4  * Copyright (C) 1999-2001 VideoLAN
5  * $Id: theora.c,v 1.10 2003/10/08 23:00:40 gbazin Exp $
6  *
7  * Authors: Gildas Bazin <gbazin@netcourrier.com>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  * 
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include <stdlib.h>                                      /* malloc(), free() */
28 #include <string.h>                                    /* memcpy(), memset() */
29
30 #include <vlc/vlc.h>
31 #include <vlc/vout.h>
32 #include <vlc/decoder.h>
33 #include <vlc/input.h>
34 #include <vlc/sout.h>
35 #include <input_ext-dec.h>
36
37 #include <ogg/ogg.h>
38
39 #include <theora/theora.h>
40
41 /*****************************************************************************
42  * decoder_sys_t : theora decoder descriptor
43  *****************************************************************************/
44 struct decoder_sys_t
45 {
46     /* Module mode */
47     vlc_bool_t b_packetizer;
48
49     /*
50      * Input properties
51      */
52     int i_headers;
53
54     /*
55      * Theora properties
56      */
57     theora_info      ti;                        /* theora bitstream settings */
58     theora_comment   tc;                            /* theora comment header */
59     theora_state     td;                   /* theora bitstream user comments */
60
61     /*
62      * Output properties
63      */
64     vout_thread_t *p_vout;
65
66     /*
67      * Packetizer output properties
68      */
69     sout_packetizer_input_t *p_sout_input;
70     sout_format_t           sout_format;
71
72     /*
73      * Common properties
74      */
75     mtime_t i_pts;
76 };
77
78 /*****************************************************************************
79  * Local prototypes
80  *****************************************************************************/
81 static int OpenDecoder   ( vlc_object_t * );
82 static int OpenPacketizer( vlc_object_t * );
83
84 static int InitDecoder   ( decoder_t * );
85 static int RunDecoder    ( decoder_t *, block_t * );
86 static int EndDecoder    ( decoder_t * );
87
88 static int ProcessPacket ( decoder_t *, ogg_packet *, mtime_t );
89 static int DecodePacket  ( decoder_t *, ogg_packet * );
90 static int SendPacket    ( decoder_t *, ogg_packet * );
91
92 static void ParseTheoraComments( decoder_t * );
93 static void theora_CopyPicture( decoder_t *, picture_t *, yuv_buffer * );
94
95 static int  OpenEncoder( vlc_object_t *p_this );
96 static void CloseEncoder( vlc_object_t *p_this );
97 static block_t *Headers( encoder_t *p_enc );
98 static block_t *Encode( encoder_t *p_enc, picture_t *p_pict );
99
100 /*****************************************************************************
101  * Module descriptor
102  *****************************************************************************/
103 vlc_module_begin();
104     set_description( _("Theora video decoder") );
105     set_capability( "decoder", 100 );
106     set_callbacks( OpenDecoder, NULL );
107     add_shortcut( "theora" );
108
109     add_submodule();
110     set_description( _("Theora video packetizer") );
111     set_capability( "packetizer", 100 );
112     set_callbacks( OpenPacketizer, NULL );
113     add_shortcut( "theora" );
114
115     add_submodule();
116     set_description( _("Theora video encoder") );
117     set_capability( "video encoder", 100 );
118     set_callbacks( OpenEncoder, CloseEncoder );
119     add_shortcut( "theora" );
120 vlc_module_end();
121
122 /*****************************************************************************
123  * OpenDecoder: probe the decoder and return score
124  *****************************************************************************/
125 static int OpenDecoder( vlc_object_t *p_this )
126 {
127     decoder_t *p_dec = (decoder_t*)p_this;
128
129     if( p_dec->p_fifo->i_fourcc != VLC_FOURCC('t','h','e','o') )
130     {
131         return VLC_EGENERIC;
132     }
133
134     p_dec->pf_init = InitDecoder;
135     p_dec->pf_decode = RunDecoder;
136     p_dec->pf_end = EndDecoder;
137
138     /* Allocate the memory needed to store the decoder's structure */
139     if( ( p_dec->p_sys =
140           (decoder_sys_t *)malloc(sizeof(decoder_sys_t)) ) == NULL )
141     {
142         msg_Err( p_dec, "out of memory" );
143         return VLC_EGENERIC;
144     }
145     p_dec->p_sys->b_packetizer = VLC_FALSE;
146
147     return VLC_SUCCESS;
148 }
149
150 static int OpenPacketizer( vlc_object_t *p_this )
151 {
152     decoder_t *p_dec = (decoder_t*)p_this;
153
154     int i_ret = OpenDecoder( p_this );
155
156     if( i_ret == VLC_SUCCESS ) p_dec->p_sys->b_packetizer = VLC_TRUE;
157
158     return i_ret;
159 }
160
161 /*****************************************************************************
162  * InitDecoder: Initalize the decoder
163  *****************************************************************************/
164 static int InitDecoder( decoder_t *p_dec )
165 {
166     decoder_sys_t *p_sys = p_dec->p_sys;
167
168     p_sys->i_pts = 0;
169
170     p_sys->p_sout_input = NULL;
171     p_sys->sout_format.i_cat = VIDEO_ES;
172     p_sys->sout_format.i_fourcc = VLC_FOURCC( 't', 'h', 'e', 'o' );
173     p_sys->sout_format.i_width  = 0;
174     p_sys->sout_format.i_height = 0;
175     p_sys->sout_format.i_bitrate     = 0;
176     p_sys->sout_format.i_extra_data  = 0;
177     p_sys->sout_format.p_extra_data  = NULL;
178
179     /* Init supporting Theora structures needed in header parsing */
180     theora_comment_init( &p_sys->tc );
181     theora_info_init( &p_sys->ti );
182
183     p_sys->i_headers = 0;
184
185     return VLC_SUCCESS;
186 }
187
188 /****************************************************************************
189  * RunDecoder: the whole thing
190  ****************************************************************************
191  * This function must be fed with ogg packets.
192  ****************************************************************************/
193 static int RunDecoder( decoder_t *p_dec, block_t *p_block )
194 {
195     decoder_sys_t *p_sys = p_dec->p_sys;
196     ogg_packet oggpacket;
197     int i_ret;
198
199     /* Block to Ogg packet */
200     oggpacket.packet = p_block->p_buffer;
201     oggpacket.bytes = p_block->i_buffer;
202     oggpacket.granulepos = p_block->i_dts;
203     oggpacket.b_o_s = 0;
204     oggpacket.e_o_s = 0;
205     oggpacket.packetno = 0;
206
207     if( p_sys->i_headers == 0 )
208     {
209         /* Take care of the initial Theora header */
210
211         oggpacket.b_o_s = 1; /* yes this actually is a b_o_s packet :) */
212         if( theora_decode_header( &p_sys->ti, &p_sys->tc, &oggpacket ) < 0 )
213         {
214             msg_Err( p_dec->p_fifo, "This bitstream does not contain Theora "
215                      "video data" );
216             block_Release( p_block );
217             return VLC_EGENERIC;
218         }
219         p_sys->i_headers++;
220
221  
222         if( p_sys->b_packetizer )
223         {
224             /* add a input for the stream ouput */
225             p_sys->sout_format.i_width  = p_sys->ti.width;
226             p_sys->sout_format.i_height = p_sys->ti.height;
227
228             p_sys->p_sout_input =
229                 sout_InputNew( p_dec, &p_sys->sout_format );
230
231             if( !p_sys->p_sout_input )
232             {
233                 msg_Err( p_dec, "cannot add a new stream" );
234                 block_Release( p_block );
235                 return VLC_EGENERIC;
236             }
237         }
238         else
239         {
240             /* Initialize video output */
241             int i_chroma, i_aspect;
242
243             if( p_sys->ti.aspect_denominator )
244                 i_aspect = VOUT_ASPECT_FACTOR * p_sys->ti.aspect_numerator /
245                     p_sys->ti.aspect_denominator;
246             else
247                 i_aspect = VOUT_ASPECT_FACTOR *
248                     p_sys->ti.frame_width / p_sys->ti.frame_height;
249
250             i_chroma = VLC_FOURCC('Y','V','1','2');
251
252             p_sys->p_vout =
253                 vout_Request( p_dec, NULL,
254                               p_sys->ti.frame_width, p_sys->ti.frame_height,
255                               i_chroma, i_aspect );
256             if( p_sys->p_vout == NULL )
257             {
258                 msg_Err( p_dec, "failed to create video output" );
259                 block_Release( p_block );
260                 return VLC_EGENERIC;
261             }
262         }
263
264         msg_Dbg( p_dec, "%dx%d %.02f fps video, frame content "
265                  "is %dx%d with offset (%d,%d)",
266                  p_sys->ti.width, p_sys->ti.height,
267                  (double)p_sys->ti.fps_numerator/p_sys->ti.fps_denominator,
268                  p_sys->ti.frame_width, p_sys->ti.frame_height,
269                  p_sys->ti.offset_x, p_sys->ti.offset_y );
270
271         if( p_sys->b_packetizer )
272         {
273             i_ret = SendPacket( p_dec, &oggpacket );
274             block_Release( p_block );
275             return i_ret;
276         }
277         else
278         {
279             block_Release( p_block );
280             return VLC_SUCCESS;
281         }
282     }
283
284     if( p_sys->i_headers == 1 )
285     {
286         /* The next packet in order is the comments header */
287         if( theora_decode_header( &p_sys->ti, &p_sys->tc, &oggpacket ) < 0 )
288         {
289             msg_Err( p_dec, "2nd Theora header is corrupted" );
290             return VLC_EGENERIC;
291         }
292         p_sys->i_headers++;
293     
294         ParseTheoraComments( p_dec );
295
296         if( p_sys->b_packetizer )
297         {
298             i_ret = SendPacket( p_dec, &oggpacket );
299             block_Release( p_block );
300             return i_ret;
301         }
302         else
303         {
304             block_Release( p_block );
305             return VLC_SUCCESS;
306         }
307     }
308
309     if( p_sys->i_headers == 2 )
310     {
311         /* The next packet in order is the codebooks header
312            We need to watch out that this packet is not missing as a
313            missing or corrupted header is fatal. */
314         if( theora_decode_header( &p_sys->ti, &p_sys->tc, &oggpacket ) < 0 )
315         {
316             msg_Err( p_dec, "3rd Theora header is corrupted" );
317             return VLC_EGENERIC;
318         }
319         p_sys->i_headers++;
320     
321         if( !p_sys->b_packetizer )
322         {
323             /* We have all the headers, initialize decoder */
324             theora_decode_init( &p_sys->td, &p_sys->ti );
325         }
326
327         if( p_sys->b_packetizer )
328         {
329             i_ret = SendPacket( p_dec, &oggpacket );
330             block_Release( p_block );
331             return i_ret;
332         }
333         else
334         {
335             block_Release( p_block );
336             return VLC_SUCCESS;
337         }
338     }
339
340     i_ret = ProcessPacket( p_dec, &oggpacket, p_block->i_pts );
341     block_Release( p_block );
342     return i_ret;
343 }
344
345 /*****************************************************************************
346  * ProcessPacket: processes a Vorbis packet.
347  *****************************************************************************/
348 static int ProcessPacket( decoder_t *p_dec, ogg_packet *p_oggpacket,
349                           mtime_t i_pts )
350 {
351     decoder_sys_t *p_sys = p_dec->p_sys;
352
353     /* Date management */
354     if( i_pts > 0 && i_pts != p_sys->i_pts )
355     {
356         p_sys->i_pts = i_pts;
357     }
358
359     if( p_sys->b_packetizer )
360     {
361         return SendPacket( p_dec, p_oggpacket );
362     }
363     else
364     {
365         return DecodePacket( p_dec, p_oggpacket );
366     }
367 }
368
369 /*****************************************************************************
370  * DecodePacket: decodes a Theora packet.
371  *****************************************************************************/
372 static int DecodePacket( decoder_t *p_dec, ogg_packet *p_oggpacket )
373 {
374     picture_t *p_pic;
375     yuv_buffer yuv;
376
377     decoder_sys_t *p_sys = p_dec->p_sys;
378
379     theora_decode_packetin( &p_sys->td, p_oggpacket );
380
381     /* Decode */
382     theora_decode_YUVout( &p_sys->td, &yuv );
383
384     /* Get a new picture */
385     while( !(p_pic = vout_CreatePicture( p_sys->p_vout, 0, 0, 0 ) ) )
386     {
387         if( p_dec->p_fifo->b_die || p_dec->p_fifo->b_error )
388         {
389             return VLC_EGENERIC;
390         }
391         msleep( VOUT_OUTMEM_SLEEP );
392     }
393     if( !p_pic ) return VLC_EGENERIC;
394
395     theora_CopyPicture( p_dec, p_pic, &yuv );
396
397     vout_DatePicture( p_sys->p_vout, p_pic, p_sys->i_pts );
398     vout_DisplayPicture( p_sys->p_vout, p_pic );
399
400     /* Date management */
401     p_sys->i_pts += ( I64C(1000000) * p_sys->ti.fps_denominator /
402                       p_sys->ti.fps_numerator ); /* 1 frame per packet */
403
404     return VLC_SUCCESS;
405 }
406
407 /*****************************************************************************
408  * SendPacket: send an ogg packet to the stream output.
409  *****************************************************************************/
410 static int SendPacket( decoder_t *p_dec, ogg_packet *p_oggpacket )
411 {
412     decoder_sys_t *p_sys = p_dec->p_sys;
413
414     sout_buffer_t *p_sout_buffer =
415         sout_BufferNew( p_sys->p_sout_input->p_sout, p_oggpacket->bytes );
416
417     if( !p_sout_buffer ) return VLC_EGENERIC;
418
419     p_dec->p_vlc->pf_memcpy( p_sout_buffer->p_buffer,
420                              p_oggpacket->packet,
421                              p_oggpacket->bytes );
422
423     /* Date management */
424     p_sout_buffer->i_dts = p_sout_buffer->i_pts = p_sys->i_pts;
425     p_sys->i_pts += ( I64C(1000000) * p_sys->ti.fps_denominator /
426                       p_sys->ti.fps_numerator ); /* 1 frame per packet */
427
428     if( p_sys->i_headers >= 3 )
429         p_sout_buffer->i_length = p_sys->i_pts - p_sout_buffer->i_pts;
430     else
431         p_sout_buffer->i_length = 0;
432
433     sout_InputSendBuffer( p_sys->p_sout_input, p_sout_buffer );
434
435     return VLC_SUCCESS;
436 }
437
438 /*****************************************************************************
439  * ParseTheoraComments: FIXME should be done in demuxer
440  *****************************************************************************/
441 static void ParseTheoraComments( decoder_t *p_dec )
442 {
443     input_thread_t *p_input = (input_thread_t *)p_dec->p_parent;
444     input_info_category_t *p_cat =
445         input_InfoCategory( p_input, _("Theora Comment") );
446     int i = 0;
447     char *psz_name, *psz_value, *psz_comment;
448     while ( i < p_dec->p_sys->tc.comments )
449     {
450         psz_comment = strdup( p_dec->p_sys->tc.user_comments[i] );
451         if( !psz_comment )
452         {
453             msg_Warn( p_dec, "Out of memory" );
454             break;
455         }
456         psz_name = psz_comment;
457         psz_value = strchr( psz_comment, '=' );
458         if( psz_value )
459         {
460             *psz_value = '\0';
461             psz_value++;
462             input_AddInfo( p_cat, psz_name, psz_value );
463         }
464         free( psz_comment );
465         i++;
466     }
467 }
468
469 /*****************************************************************************
470  * EndDecoder: theora decoder destruction
471  *****************************************************************************/
472 static int EndDecoder( decoder_t *p_dec )
473 {
474     decoder_sys_t *p_sys = p_dec->p_sys;
475
476     if( !p_sys->b_packetizer )
477         vout_Request( p_dec, p_sys->p_vout, 0, 0, 0, 0 );
478
479     if( p_sys->p_sout_input != NULL )
480     {
481         sout_InputDelete( p_sys->p_sout_input );
482     }
483
484     theora_info_clear( &p_sys->ti );
485     theora_comment_clear( &p_sys->tc );
486
487     free( p_sys );
488
489     return VLC_SUCCESS;
490 }
491
492 /*****************************************************************************
493  * theora_CopyPicture: copy a picture from theora internal buffers to a
494  *                     picture_t structure.
495  *****************************************************************************/
496 static void theora_CopyPicture( decoder_t *p_dec, picture_t *p_pic,
497                                 yuv_buffer *yuv )
498 {
499     int i_plane, i_line, i_width, i_dst_stride, i_src_stride;
500     int i_src_xoffset, i_src_yoffset;
501     u8  *p_dst, *p_src;
502
503     for( i_plane = 0; i_plane < p_pic->i_planes; i_plane++ )
504     {
505         p_dst = p_pic->p[i_plane].p_pixels;
506         p_src = i_plane ? (i_plane - 1 ? yuv->v : yuv->u ) : yuv->y;
507         i_width = p_pic->p[i_plane].i_visible_pitch;
508         i_dst_stride  = p_pic->p[i_plane].i_pitch;
509         i_src_stride  = i_plane ? yuv->uv_stride : yuv->y_stride;
510         i_src_xoffset = p_dec->p_sys->ti.offset_x;
511         i_src_yoffset = p_dec->p_sys->ti.offset_y;
512         if( i_plane )
513         {
514             i_src_xoffset /= 2;
515             i_src_yoffset /= 2;
516         } 
517
518         p_src += (i_src_yoffset * i_src_stride + i_src_yoffset);
519
520         for( i_line = 0; i_line < p_pic->p[i_plane].i_lines; i_line++ )
521         {
522             p_dec->p_vlc->pf_memcpy( p_dst, p_src, i_width );
523             p_src += i_src_stride;
524             p_dst += i_dst_stride;
525         }
526     }
527 }
528
529 /*****************************************************************************
530  * encoder_sys_t : theora encoder descriptor
531  *****************************************************************************/
532 struct encoder_sys_t
533 {
534     /*
535      * Input properties
536      */
537     int i_headers;
538
539     /*
540      * Theora properties
541      */
542     theora_info      ti;                        /* theora bitstream settings */
543     theora_comment   tc;                            /* theora comment header */
544     theora_state     td;                   /* theora bitstream user comments */
545
546     /*
547      * Packetizer output properties
548      */
549     sout_packetizer_input_t *p_sout_input;
550     sout_format_t           sout_format;
551
552     /*
553      * Common properties
554      */
555     mtime_t i_pts;
556 };
557
558 /*****************************************************************************
559  * OpenEncoder: probe the encoder and return score
560  *****************************************************************************/
561 static int OpenEncoder( vlc_object_t *p_this )
562 {
563     encoder_t *p_enc = (encoder_t *)p_this;
564     encoder_sys_t *p_sys = p_enc->p_sys;
565
566     if( p_enc->i_fourcc != VLC_FOURCC('t','h','e','o') )
567     {
568         return VLC_EGENERIC;
569     }
570
571     /* Allocate the memory needed to store the decoder's structure */
572     if( ( p_sys = (encoder_sys_t *)malloc(sizeof(encoder_sys_t)) ) == NULL )
573     {
574         msg_Err( p_enc, "out of memory" );
575         return VLC_EGENERIC;
576     }
577     p_enc->p_sys = p_sys;
578
579     p_enc->pf_header = Headers;
580     p_enc->pf_encode_video = Encode;
581     p_enc->format.video.i_chroma = VLC_FOURCC('I','4','2','0');
582
583 #define frame_x_offset 0
584 #define frame_y_offset 0
585 #define video_hzn 25
586 #define video_hzd 1
587 #define video_an 4
588 #define video_ad 3
589 #define video_q 5
590
591     theora_info_init( &p_sys->ti );
592
593     p_sys->ti.width = p_enc->format.video.i_width;
594     p_sys->ti.height = p_enc->format.video.i_height;
595     p_sys->ti.frame_width = p_enc->format.video.i_width;
596     p_sys->ti.frame_height = p_enc->format.video.i_height;
597     p_sys->ti.offset_x = frame_x_offset;
598     p_sys->ti.offset_y = frame_y_offset;
599     p_sys->ti.fps_numerator = video_hzn;
600     p_sys->ti.fps_denominator = video_hzd;
601     p_sys->ti.aspect_numerator = video_an;
602     p_sys->ti.aspect_denominator = video_ad;
603     p_sys->ti.colorspace = not_specified;
604     p_sys->ti.target_bitrate = p_enc->i_bitrate;
605     p_sys->ti.quality = video_q;
606
607     p_sys->ti.dropframes_p = 0;
608     p_sys->ti.quick_p = 1;
609     p_sys->ti.keyframe_auto_p = 1;
610     p_sys->ti.keyframe_frequency = 64;
611     p_sys->ti.keyframe_frequency_force = 64;
612     p_sys->ti.keyframe_data_target_bitrate = p_enc->i_bitrate * 1.5;
613     p_sys->ti.keyframe_auto_threshold = 80;
614     p_sys->ti.keyframe_mindistance = 8;
615     p_sys->ti.noise_sensitivity = 1;
616
617     theora_encode_init( &p_sys->td, &p_sys->ti );
618     theora_info_clear( &p_sys->ti );
619     theora_comment_init( &p_sys->tc );
620
621     p_sys->i_headers = 0;
622
623     return VLC_SUCCESS;
624 }
625
626 /****************************************************************************
627  * Encode: the whole thing
628  ****************************************************************************
629  * This function spits out ogg packets.
630  ****************************************************************************/
631 static block_t *Headers( encoder_t *p_enc )
632 {
633     encoder_sys_t *p_sys = p_enc->p_sys;
634     ogg_packet oggpacket;
635     block_t *p_block;
636
637     /* Create theora headers */
638     switch( p_sys->i_headers )
639     {
640     case 0:
641         theora_encode_header( &p_sys->td, &oggpacket );
642         break;
643     case 1:
644         theora_encode_comment( &p_sys->tc, &oggpacket );
645         break;
646     case 2:
647         theora_encode_tables( &p_sys->td, &oggpacket );
648         break;
649     default:
650         break;
651     }
652
653     p_sys->i_headers++;
654     if( p_sys->i_headers > 3 ) return NULL;
655
656     /* Ogg packet to block */
657     p_block = block_New( p_enc, oggpacket.bytes );
658     p_block->p_buffer = oggpacket.packet;
659     p_block->i_buffer = oggpacket.bytes;
660     p_block->i_dts = oggpacket.granulepos;
661
662     return p_block;
663 }
664
665 /****************************************************************************
666  * Encode: the whole thing
667  ****************************************************************************
668  * This function spits out ogg packets.
669  ****************************************************************************/
670 static block_t *Encode( encoder_t *p_enc, picture_t *p_pict )
671 {
672     encoder_sys_t *p_sys = p_enc->p_sys;
673     ogg_packet oggpacket;
674     block_t *p_block;
675     yuv_buffer yuv;
676
677     /* Theora is a one-frame-in, one-frame-out system. Submit a frame
678      * for compression and pull out the packet. */
679
680     yuv.y_width  = p_pict->p[0].i_visible_pitch;
681     yuv.y_height = p_pict->p[0].i_lines;
682     yuv.y_stride = p_pict->p[0].i_pitch;
683
684     yuv.uv_width  = p_pict->p[1].i_visible_pitch;
685     yuv.uv_height = p_pict->p[1].i_lines;
686     yuv.uv_stride = p_pict->p[1].i_pitch;
687
688     yuv.y = p_pict->p[0].p_pixels;
689     yuv.u = p_pict->p[1].p_pixels;
690     yuv.v = p_pict->p[2].p_pixels;
691
692     theora_encode_YUVin( &p_sys->td, &yuv );
693
694     theora_encode_packetout( &p_sys->td, 0, &oggpacket );
695
696     /* Ogg packet to block */
697     p_block = block_New( p_enc, oggpacket.bytes );
698     memcpy( p_block->p_buffer, oggpacket.packet, oggpacket.bytes );
699     p_block->i_dts = p_pict->date;//oggpacket.granulepos;
700
701     return p_block;
702 }
703
704 /*****************************************************************************
705  * CloseEncoder: theora encoder destruction
706  *****************************************************************************/
707 static void CloseEncoder( vlc_object_t *p_this )
708 {
709     encoder_t *p_enc = (encoder_t *)p_this;
710     encoder_sys_t *p_sys = p_enc->p_sys;
711
712     theora_info_clear( &p_sys->ti );
713     //theora_comment_clear( &p_sys->tc );
714
715     free( p_sys );
716 }