/*****************************************************************************
- * dec_dummy.c: dummy decoder plugin for vlc.
+ * decoder.c: dummy decoder plugin for vlc.
*****************************************************************************
- * Copyright (C) 2002 VideoLAN
- * $Id: decoder.c,v 1.3 2002/10/27 16:58:13 gbazin Exp $
+ * Copyright (C) 2002 the VideoLAN team
+ * $Id$
*
* Authors: Samuel Hocevar <sam@zoy.org>
- *
+ *
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
/*****************************************************************************
* Preamble
*****************************************************************************/
-#include <vlc/vlc.h>
-#include <vlc/decoder.h>
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+#include <vlc_common.h>
+#include <vlc_codec.h>
+#include <vlc_fs.h>
+
+#include <sys/types.h>
#ifdef HAVE_UNISTD_H
# include <unistd.h> /* write(), close() */
+#elif defined( WIN32 ) && !defined( UNDER_CE )
+# include <io.h>
+#endif
+#ifdef HAVE_FCNTL_H
+# include <fcntl.h>
#endif
-#include <sys/types.h> /* open() */
-#include <sys/stat.h>
-#include <fcntl.h>
+#include <limits.h> /* PATH_MAX */
-#include <stdio.h> /* sprintf() */
-/*****************************************************************************
- * Local prototypes
- *****************************************************************************/
-static int Run ( decoder_fifo_t * );
+#include "dummy.h"
/*****************************************************************************
- * OpenDecoder: probe the decoder and return score
- *****************************************************************************
- * Always returns 0 because we are the dummy decoder!
+ * decoder_sys_t : theora decoder descriptor
*****************************************************************************/
-int E_(OpenDecoder) ( vlc_object_t *p_this )
+struct decoder_sys_t
{
- ((decoder_fifo_t*)p_this)->pf_run = Run;
+ int i_fd;
+};
- return VLC_SUCCESS;
-}
+/*****************************************************************************
+ * Local prototypes
+ *****************************************************************************/
+static void *DecodeBlock( decoder_t *p_dec, block_t **pp_block );
/*****************************************************************************
- * Run: this function is called just after the thread is created
+ * OpenDecoder: Open the decoder
*****************************************************************************/
-static int Run ( decoder_fifo_t *p_fifo )
+static int OpenDecoderCommon( vlc_object_t *p_this, bool b_force_dump )
{
- u8 p_buffer[1024];
-
- bit_stream_t bit_stream;
- mtime_t last_date = mdate();
- size_t i_bytes = 0;
+ decoder_t *p_dec = (decoder_t*)p_this;
+ decoder_sys_t *p_sys;
+ char psz_file[ PATH_MAX ];
- char psz_file[100];
- int i_fd;
-
- sprintf( psz_file, "stream.%i", p_fifo->i_object_id );
- i_fd = open( psz_file, O_WRONLY | O_CREAT | O_TRUNC, 00644 );
-
- if( i_fd == -1 )
+ /* Allocate the memory needed to store the decoder's structure */
+ if( ( p_dec->p_sys = p_sys =
+ (decoder_sys_t *)malloc(sizeof(decoder_sys_t)) ) == NULL )
{
- msg_Err( p_fifo, "cannot create `%s'", psz_file );
- p_fifo->b_error = 1;
- DecoderError( p_fifo );
- return -1;
+ return VLC_ENOMEM;
}
- msg_Dbg( p_fifo, "dumping stream to file `%s'", psz_file );
+ snprintf( psz_file, sizeof( psz_file), "stream.%p", p_dec );
- if( InitBitstream( &bit_stream, p_fifo, NULL, NULL ) != VLC_SUCCESS )
+#ifndef UNDER_CE
+ if( !b_force_dump )
{
- msg_Err( p_fifo, "cannot initialize bitstream" );
- p_fifo->b_error = 1;
- DecoderError( p_fifo );
- close( i_fd );
- return -1;
+ b_force_dump = var_CreateGetBool( p_dec, "dummy-save-es" );
}
-
- while( !p_fifo->b_die && !p_fifo->b_error )
+ if( b_force_dump )
{
- GetChunk( &bit_stream, p_buffer, 1024 );
- write( i_fd, p_buffer, 1024 );
+ p_sys->i_fd = vlc_open( psz_file, O_WRONLY | O_CREAT | O_TRUNC, 00644 );
- i_bytes += 1024;
-
- if( mdate() < last_date + 2000000 )
+ if( p_sys->i_fd == -1 )
{
- continue;
+ msg_Err( p_dec, "cannot create `%s'", psz_file );
+ free( p_sys );
+ return VLC_EGENERIC;
}
- msg_Dbg( p_fifo, "dumped %i bytes", i_bytes );
-
- i_bytes = 0;
- last_date = mdate();
+ msg_Dbg( p_dec, "dumping stream to file `%s'", psz_file );
}
-
- if( i_bytes )
+ else
+#endif
{
- msg_Dbg( p_fifo, "dumped %i bytes", i_bytes );
+ p_sys->i_fd = -1;
}
- close( i_fd );
- CloseBitstream( &bit_stream );
+ /* Set callbacks */
+ p_dec->pf_decode_video = (picture_t *(*)(decoder_t *, block_t **))
+ DecodeBlock;
+ p_dec->pf_decode_audio = (aout_buffer_t *(*)(decoder_t *, block_t **))
+ DecodeBlock;
+ p_dec->pf_decode_sub = (subpicture_t *(*)(decoder_t *, block_t **))
+ DecodeBlock;
+
+ es_format_Copy( &p_dec->fmt_out, &p_dec->fmt_in );
- if( p_fifo->b_error )
+ return VLC_SUCCESS;
+}
+
+int OpenDecoder( vlc_object_t *p_this )
+{
+ return OpenDecoderCommon( p_this, false );
+}
+int OpenDecoderDump( vlc_object_t *p_this )
+{
+ return OpenDecoderCommon( p_this, true );
+}
+
+/****************************************************************************
+ * RunDecoder: the whole thing
+ ****************************************************************************
+ * This function must be fed with ogg packets.
+ ****************************************************************************/
+static void *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
+{
+ decoder_sys_t *p_sys = p_dec->p_sys;
+ block_t *p_block;
+
+ if( !pp_block || !*pp_block ) return NULL;
+ p_block = *pp_block;
+
+ if( p_sys->i_fd >= 0 &&
+ p_block->i_buffer > 0 &&
+ (p_block->i_flags & (BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED) ) == 0 )
{
- DecoderError( p_fifo );
- return -1;
+#ifndef UNDER_CE
+ write( p_sys->i_fd, p_block->p_buffer, p_block->i_buffer );
+#endif
+
+ msg_Dbg( p_dec, "dumped %zu bytes", p_block->i_buffer );
}
- return 0;
+ block_Release( p_block );
+ return NULL;
}
+
+/*****************************************************************************
+ * CloseDecoder: decoder destruction
+ *****************************************************************************/
+void CloseDecoder ( vlc_object_t *p_this )
+{
+ decoder_t *p_dec = (decoder_t *)p_this;
+ decoder_sys_t *p_sys = p_dec->p_sys;
+
+#ifndef UNDER_CE
+ if( p_sys->i_fd >= 0 )
+ close( p_sys->i_fd );
+#endif
+
+ free( p_sys );
+}
+