]> git.sesse.net Git - vlc/blob - modules/misc/stats/decoder.c
Merge branch 1.0-bugfix
[vlc] / modules / misc / stats / decoder.c
1 /*****************************************************************************
2  * decoder.c: stats decoder plugin for vlc.
3  *****************************************************************************
4  * Copyright (C) 2002-2008 the VideoLAN team
5  *
6  * Authors: Samuel Hocevar <sam@zoy.org>
7  *          Pierre d'Herbemont <pdherbemont@videolan.org>
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
30
31 #include <vlc_common.h>
32 #include <vlc_codec.h>
33
34 #include "stats.h"
35
36 /*****************************************************************************
37  * Local prototypes
38  *****************************************************************************/
39 static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block );
40
41 /*****************************************************************************
42  * OpenDecoder: Open the decoder
43  *****************************************************************************/
44 int OpenDecoder ( vlc_object_t *p_this )
45 {
46     decoder_t *p_dec = (decoder_t*)p_this;
47
48     msg_Dbg( p_this, "opening stats decoder" );
49
50     /* Set callbacks */
51     p_dec->pf_decode_video = DecodeBlock;
52     p_dec->pf_decode_audio = NULL;
53     p_dec->pf_decode_sub = NULL;
54
55     /* */
56     es_format_Init( &p_dec->fmt_out, VIDEO_ES, VLC_CODEC_I420 );
57     p_dec->fmt_out.video.i_width = 100;
58     p_dec->fmt_out.video.i_height = 100;
59     p_dec->fmt_out.video.i_aspect = VOUT_ASPECT_FACTOR;
60
61     return VLC_SUCCESS;
62 }
63
64 /****************************************************************************
65  * RunDecoder: the whole thing
66  ****************************************************************************/
67 static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
68 {
69     block_t *p_block;
70     picture_t * p_pic = NULL;
71
72     if( !pp_block || !*pp_block ) return NULL;
73     p_block = *pp_block;
74
75     p_pic = decoder_NewPicture( p_dec );
76
77     if( p_block->i_buffer == kBufferSize )
78     {
79         msg_Dbg( p_dec, "got %"PRIu64" ms",
80                  *(mtime_t *)p_block->p_buffer  / 1000 );
81         msg_Dbg( p_dec, "got %"PRIu64" ms offset",
82                  (mdate() - *(mtime_t *)p_block->p_buffer) / 1000 );
83         *(mtime_t *)(p_pic->p->p_pixels) = *(mtime_t *)p_block->p_buffer;
84     }
85     else
86     {
87         msg_Dbg( p_dec, "got a packet not from stats demuxer" );
88         *(mtime_t *)(p_pic->p->p_pixels) = mdate();
89     }
90
91     p_pic->date = p_block->i_pts ? p_block->i_pts : p_block->i_dts;
92     p_pic->b_force = true;
93
94     block_Release( p_block );
95     *pp_block = NULL;
96     return p_pic;
97 }
98
99 /*****************************************************************************
100  * CloseDecoder: decoder destruction
101  *****************************************************************************/
102 void CloseDecoder ( vlc_object_t *p_this )
103 {
104     msg_Dbg( p_this, "closing stats decoder" );
105 }