packetizer: hevc: don't double store poc prev msb/lsb
[vlc.git] / modules / stream_out / description.c
blobbf77ba3a335f99626f9bebf55737b8b8b611920c
1 /*****************************************************************************
2 * description.c: description stream output module (gathers ES info)
3 *****************************************************************************
4 * Copyright (C) 2003-2004 VLC authors and VideoLAN
5 * $Id$
7 * Authors: Gildas Bazin <gbazin@videolan.org>
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU Lesser General Public License as published by
11 * the Free Software Foundation; either version 2.1 of the License, or
12 * (at your option) any later version.
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 Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this program; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /*****************************************************************************
25 * Preamble
26 *****************************************************************************/
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
32 #include <vlc_common.h>
33 #include <vlc_plugin.h>
34 #include <vlc_input.h>
35 #include <vlc_block.h>
36 #include <vlc_sout.h>
38 #include <assert.h>
40 /*****************************************************************************
41 * Exported prototypes
42 *****************************************************************************/
43 static int Open ( vlc_object_t * );
44 static void Close ( vlc_object_t * );
46 static sout_stream_id_sys_t *Add ( sout_stream_t *, const es_format_t * );
47 static void Del ( sout_stream_t *, sout_stream_id_sys_t * );
48 static int Send( sout_stream_t *, sout_stream_id_sys_t *, block_t* );
50 /*****************************************************************************
51 * Module descriptor
52 *****************************************************************************/
53 vlc_module_begin ()
54 set_description( N_("Description stream output") )
55 set_capability( "sout stream", 50 )
56 add_shortcut( "description" )
57 set_callbacks( Open, Close )
58 vlc_module_end ()
60 struct sout_stream_sys_t
62 sout_description_data_t *data;
63 mtime_t i_stream_start;
66 /*****************************************************************************
67 * Open:
68 *****************************************************************************/
69 static int Open( vlc_object_t *p_this )
71 sout_stream_t *p_stream = (sout_stream_t*)p_this;
72 sout_stream_sys_t *p_sys = malloc(sizeof(sout_stream_sys_t));
73 if( unlikely(p_sys == NULL) )
74 return VLC_ENOMEM;
76 p_stream->pf_add = Add;
77 p_stream->pf_del = Del;
78 p_stream->pf_send = Send;
79 p_stream->p_sys = p_sys;
81 p_sys->data = var_InheritAddress(p_stream, "sout-description-data");
82 if (p_sys->data == NULL)
84 msg_Err(p_stream, "Missing data: the description stream output is "
85 "not meant to be used without special setup from the core");
86 free(p_sys);
87 return VLC_EGENERIC;
89 p_sys->i_stream_start = 0;
91 return VLC_SUCCESS;
94 /*****************************************************************************
95 * Close:
96 *****************************************************************************/
97 static void Close( vlc_object_t *p_this )
99 sout_stream_t *p_stream = (sout_stream_t *)p_this;
100 sout_stream_sys_t *p_sys = p_stream->p_sys;
102 msg_Dbg( p_this, "Closing" );
104 free( p_sys );
107 static sout_stream_id_sys_t *Add( sout_stream_t *p_stream, const es_format_t *p_fmt )
109 sout_stream_sys_t *p_sys = p_stream->p_sys;
110 es_format_t *p_fmt_copy = malloc( sizeof( *p_fmt_copy ) );
112 if( unlikely(p_fmt_copy == NULL ) )
113 return NULL;
115 msg_Dbg( p_stream, "Adding a stream" );
116 es_format_Copy( p_fmt_copy, p_fmt );
118 TAB_APPEND( p_sys->data->i_es, p_sys->data->es, p_fmt_copy );
120 if( p_sys->i_stream_start <= 0 )
121 p_sys->i_stream_start = mdate();
123 return (void *)p_fmt_copy;
126 static void Del( sout_stream_t *p_stream, sout_stream_id_sys_t *id )
128 msg_Dbg( p_stream, "Removing a stream" );
129 /* NOTE: id should be freed by the input manager, not here. */
130 (void) id;
133 static int Send( sout_stream_t *p_stream, sout_stream_id_sys_t *id,
134 block_t *p_buffer )
136 VLC_UNUSED(id);
137 sout_stream_sys_t *p_sys = p_stream->p_sys;
139 block_ChainRelease( p_buffer );
141 if( p_sys->i_stream_start + 1500000 < mdate() )
142 vlc_sem_post(p_sys->data->sem);
144 return VLC_SUCCESS;