TARGET = ../libmltffmpeg.so
OBJS = factory.o \
- producer_ffmpeg.o \
- filter_ffmpeg_dub.o \
- consumer_ffmpeg.o
+ producer_ffmpeg.o
CFLAGS += -I../..
ffmpeg libmltffmpeg.so
EOF
-cat << EOF >> ../filters.dat
-ffmpeg_dub libmltffmpeg.so
-EOF
-
-cat << EOF >> ../consumers.dat
-ffmpeg libmltffmpeg.so
-EOF
-
fi
+++ /dev/null
-/*
- * consumer_ffmpeg.c -- an ffmpeg consumer
- * Copyright (C) 2003-2004 Ushodaya Enterprises Limited
- * Author: Charles Yates <charles.yates@pandora.be>
- *
- * 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
- * GNU General Public License for more details.
- *
- * 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-1307, USA.
- */
-
-#include "consumer_ffmpeg.h"
-#include <framework/mlt_frame.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <pthread.h>
-
-/** This classes definition.
-*/
-
-typedef struct consumer_ffmpeg_s *consumer_ffmpeg;
-
-struct consumer_ffmpeg_s
-{
- struct mlt_consumer_s parent;
- mlt_properties properties;
- int format;
- int video;
- pthread_t thread;
- int running;
- uint8_t audio_buffer[ 4096 * 3 ];
- int audio_avail;
- pthread_mutex_t audio_mutex;
- pthread_cond_t audio_cond;
- int window_width;
- int window_height;
- float aspect_ratio;
- int width;
- int height;
- int playing;
- mlt_frame *queue;
- int size;
- int count;
- uint8_t *buffer;
-};
-
-/** Forward references to static functions.
-*/
-
-static void consumer_close( mlt_consumer parent );
-static void *consumer_thread( void * );
-
-/** This is what will be called by the factory - anything can be passed in
- via the argument, but keep it simple.
-*/
-
-mlt_consumer consumer_ffmpeg_init( char *arg )
-{
- // Create the consumer object
- consumer_ffmpeg this = calloc( sizeof( struct consumer_ffmpeg_s ), 1 );
-
- // If no malloc'd and consumer init ok
- if ( this != NULL && mlt_consumer_init( &this->parent, this ) == 0 )
- {
- // Get the parent consumer object
- mlt_consumer parent = &this->parent;
-
- // We have stuff to clean up, so override the close method
- parent->close = consumer_close;
-
- // get a handle on properties
- mlt_service service = mlt_consumer_service( parent );
- this->properties = mlt_service_properties( service );
-
- // This is the initialisation of the consumer
- this->running = 1;
- pthread_mutex_init( &this->audio_mutex, NULL );
- pthread_cond_init( &this->audio_cond, NULL);
-
- // process actual param
- if ( arg == NULL || !strcmp( arg, "-" ) )
- {
- mlt_properties_set( this->properties, "video_file", "-" );
- mlt_properties_set( this->properties, "video_format", "dv" );
- }
- else
- {
- mlt_properties_set( this->properties, "video_file", arg );
- mlt_properties_set( this->properties, "video_format", "" );
- }
-
- // Create the the thread
- pthread_create( &this->thread, NULL, consumer_thread, this );
-
- // Return the consumer produced
- return parent;
- }
-
- // malloc or consumer init failed
- free( this );
-
- // Indicate failure
- return NULL;
-}
-
-static void sdl_fill_audio( void *udata, uint8_t *stream, int len )
-{
- consumer_ffmpeg this = udata;
-
- pthread_mutex_lock( &this->audio_mutex );
-
- // Block until audio received
- while ( this->running && len > this->audio_avail )
- pthread_cond_wait( &this->audio_cond, &this->audio_mutex );
-
- if ( this->audio_avail >= len )
- {
- // Remove len from the audio available
- this->audio_avail -= len;
-
- // Remove the samples
- memmove( this->audio_buffer, this->audio_buffer + len, this->audio_avail );
- }
- else
- {
- // Just to be safe, wipe the stream first
- memset( stream, 0, len );
-
- // Copy what we have into the stream
- memcpy( stream, this->audio_buffer, this->audio_avail );
-
- // No audio left
- this->audio_avail = 0;
- }
-
- pthread_cond_broadcast( &this->audio_cond );
- pthread_mutex_unlock( &this->audio_mutex );
-}
-
-static int consumer_play_audio( consumer_ffmpeg this, mlt_frame frame, int init_audio )
-{
- // Get the properties of this consumer
- mlt_properties properties = this->properties;
- mlt_audio_format afmt = mlt_audio_pcm;
- int channels;
- int samples;
- int frequency;
- int16_t *pcm;
- int bytes;
-
- mlt_frame_get_audio( frame, &pcm, &afmt, &frequency, &channels, &samples );
-
- if ( mlt_properties_get_int( properties, "audio_off" ) )
- return init_audio;
-
- if ( init_audio == 0 )
- {
- bytes = ( samples * channels * 2 );
- pthread_mutex_lock( &this->audio_mutex );
- while ( bytes > ( sizeof( this->audio_buffer) - this->audio_avail ) )
- pthread_cond_wait( &this->audio_cond, &this->audio_mutex );
- mlt_properties properties = mlt_frame_properties( frame );
- if ( mlt_properties_get_double( properties, "_speed" ) == 1 )
- memcpy( &this->audio_buffer[ this->audio_avail ], pcm, bytes );
- else
- memset( &this->audio_buffer[ this->audio_avail ], 0, bytes );
- this->audio_avail += bytes;
- pthread_cond_broadcast( &this->audio_cond );
- pthread_mutex_unlock( &this->audio_mutex );
- }
- else
- {
- this->playing = 1;
- }
-
- return init_audio;
-}
-
-static int consumer_play_video( consumer_ffmpeg this, mlt_frame frame )
-{
- // Get the properties of this consumer
- mlt_properties properties = this->properties;
-
- if ( mlt_properties_get_int( properties, "video_off" ) )
- {
- mlt_frame_close( frame );
- return 0;
- }
-
- if ( this->count == this->size )
- {
- this->size += 25;
- this->queue = realloc( this->queue, sizeof( mlt_frame ) * this->size );
- }
- this->queue[ this->count ++ ] = frame;
-
- // We're working on the oldest frame now
- frame = this->queue[ 0 ];
-
- // Shunt the frames in the queue down
- int i = 0;
- for ( i = 1; i < this->count; i ++ )
- this->queue[ i - 1 ] = this->queue[ i ];
- this->count --;
-
- return 0;
-}
-
-/** Threaded wrapper for pipe.
-*/
-
-static void *consumer_thread( void *arg )
-{
- // Identify the arg
- consumer_ffmpeg this = arg;
-
- // Get the consumer
- mlt_consumer consumer = &this->parent;
-
- // Get the service assoicated to the consumer
- mlt_service service = mlt_consumer_service( consumer );
-
- // Define a frame pointer
- mlt_frame frame;
-
- // internal intialization
- int init_audio = 1;
-
- // Loop until told not to
- while( this->running )
- {
- // Get a frame from the service (should never return anything other than 0)
- if ( mlt_service_get_frame( service, &frame, 0 ) == 0 )
- {
- init_audio = consumer_play_audio( this, frame, init_audio );
- consumer_play_video( this, frame );
- }
- }
-
- return NULL;
-}
-
-/** Callback to allow override of the close method.
-*/
-
-static void consumer_close( mlt_consumer parent )
-{
- // Get the actual object
- consumer_ffmpeg this = parent->child;
-
- // Kill the thread and clean up
- this->running = 0;
-
- pthread_mutex_lock( &this->audio_mutex );
- pthread_cond_broadcast( &this->audio_cond );
- pthread_mutex_unlock( &this->audio_mutex );
-
- pthread_join( this->thread, NULL );
- pthread_mutex_destroy( &this->audio_mutex );
- pthread_cond_destroy( &this->audio_cond );
-
- // Now clean up the rest (the close = NULL is a bit nasty but needed for now)
- parent->close = NULL;
- mlt_consumer_close( parent );
-
- // Finally clean up this
- free( this );
-}
-
+++ /dev/null
-/*
- * consumer_ffmpeg.h -- simple ffmpeg test case
- * Copyright (C) 2003-2004 Ushodaya Enterprises Limited
- * Author: Charles Yates <charles.yates@pandora.be>
- *
- * 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
- * GNU General Public License for more details.
- *
- * 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-1307, USA.
- */
-
-#ifndef _CONSUMER_FFMPEG_H_
-#define _CONSUMER_FFMPEG_H_
-
-#include <framework/mlt_consumer.h>
-
-extern mlt_consumer consumer_ffmpeg_init( char *file );
-
-#endif
#include <string.h>
#include "producer_ffmpeg.h"
-#include "filter_ffmpeg_dub.h"
-#include "consumer_ffmpeg.h"
void *mlt_create_producer( char *id, void *arg )
{
void *mlt_create_filter( char *id, void *arg )
{
- if ( !strcmp( id, "ffmpeg_dub" ) )
- return filter_ffmpeg_dub_init( arg );
return NULL;
}
void *mlt_create_consumer( char *id, void *arg )
{
- if ( !strcmp( id, "ffmpeg" ) )
- return consumer_ffmpeg_init( arg );
return NULL;
}
+++ /dev/null
-/*
- * filter_ffmpeg_dub.c -- simple ffmpeg dub test case
- * Copyright (C) 2003-2004 Ushodaya Enterprises Limited
- * Author: Charles Yates <charles.yates@pandora.be>
- *
- * 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
- * GNU General Public License for more details.
- *
- * 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-1307, USA.
- */
-
-#include "filter_ffmpeg_dub.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <framework/mlt.h>
-
-/** Do it.
-*/
-
-static int filter_get_audio( mlt_frame frame, int16_t **buffer, mlt_audio_format *format, int *frequency, int *channels, int *samples )
-{
- // Obtain the frame properties
- mlt_properties frame_properties = mlt_frame_properties( frame );
-
- // Get the producer used.
- mlt_producer producer = mlt_properties_get_data( frame_properties, "producer", NULL );
-
- // Get the producer properties
- mlt_properties producer_properties = mlt_producer_properties( producer );
-
- // Get the original get_audio
- frame->get_audio = mlt_properties_get_data( frame_properties, "get_audio", NULL );
-
- // Call the original get_audio
- mlt_frame_get_audio( frame, buffer, format, frequency, channels, samples );
-
- // Now if our producer is still producing, override the audio
- if ( !mlt_properties_get_int( producer_properties, "end_of_clip" ) )
- {
- // Get the position
- mlt_position position = mlt_properties_get_position( producer_properties, "dub_position" );
-
- // We need a frame from the producer
- mlt_frame producer_frame;
-
- // Set the FPS
- mlt_properties_set_double( producer_properties, "fps", mlt_properties_get_double( frame_properties, "fps" ) );
-
- // Seek to the position
- mlt_producer_seek( producer, position );
-
- // Get the next frame
- producer->get_frame( producer, &producer_frame, 0 );
-
- if ( !mlt_properties_get_int( producer_properties, "end_of_clip" ) )
- {
- // Now get the audio from this frame
- producer_frame->get_audio( producer_frame, buffer, format, frequency, channels, samples );
-
- // This producer frame will be destroyed automatically when frame is destroyed
- mlt_properties_set_data( frame_properties, "ffmpeg_dub_frame", producer_frame, 0, ( mlt_destructor )mlt_frame_close, NULL );
-
- // Incrment the position
- mlt_properties_set_position( producer_properties, "dub_position", position + 1 );
- }
- }
-
- return 0;
-}
-
-/** Filter processing.
-*/
-
-static mlt_frame filter_process( mlt_filter this, mlt_frame frame )
-{
- // Obtain the filter properties
- mlt_properties filter_properties = mlt_filter_properties( this );
-
- // Get the producer used.
- mlt_producer producer = mlt_properties_get_data( filter_properties, "producer", NULL );
-
- // Obtain the frame properties
- mlt_properties frame_properties = mlt_frame_properties( frame );
-
- // Get the producer properties
- mlt_properties producer_properties = mlt_producer_properties( producer );
-
- // Only do this if we have not reached end of clip and ffmpeg_dub has not already been done
- if ( !mlt_properties_get_int( producer_properties, "end_of_clip" ) &&
- mlt_properties_get_data( frame_properties, "get_audio", NULL ) == NULL )
- {
- // Backup the original get_audio (it's still needed)
- mlt_properties_set_data( frame_properties, "get_audio", frame->get_audio, 0, NULL, NULL );
-
- // Pass the producer on the frame
- mlt_properties_set_data( frame_properties, "producer", producer, 0, NULL, NULL );
-
- // Override the get_audio method
- frame->get_audio = filter_get_audio;
- }
-
- return frame;
-}
-
-/** Constructor for the filter.
-*/
-
-mlt_filter filter_ffmpeg_dub_init( char *file )
-{
- // Create the filter object
- mlt_filter this = mlt_filter_new( );
-
- // Initialise it
- if ( this != NULL )
- {
- // Obtain the properties
- mlt_properties properties = mlt_filter_properties( this );
-
- // Create an ffmpeg producer
- // TODO: THIS SHOULD NOT BE HERE....
- mlt_producer producer = mlt_factory_producer( "ffmpeg", file );
-
- // Overide the filter process method
- this->process = filter_process;
-
- // Pass the producer
- mlt_properties_set_data( properties, "producer", producer, 0, ( mlt_destructor )mlt_producer_close, NULL );
-
- // Initialise the audio frame position
- mlt_properties_set_position( properties, "dub_position", 0 );
- }
-
- return this;
-}
-
+++ /dev/null
-/*
- * filter_ffmpeg_dub.h -- simple ffmpeg dub test case
- * Copyright (C) 2003-2004 Ushodaya Enterprises Limited
- * Author: Charles Yates <charles.yates@pandora.be>
- *
- * 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
- * GNU General Public License for more details.
- *
- * 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-1307, USA.
- */
-
-#ifndef _FILTER_FFMPEG_DUB_H_
-#define _FILTER_FFMPEG_DUB_H_
-
-#include <framework/mlt_filter.h>
-
-extern mlt_filter filter_ffmpeg_dub_init( char *file );
-
-#endif