X-Git-Url: http://research.m1stereo.tv/gitweb?a=blobdiff_plain;f=src%2Fmodules%2Fcore%2Fproducer_noise.c;h=825f5912493f3def1b37289bad2838681275c373;hb=cdf8aba7c1a3ad2ea9a7226c932d7d7d38a6d1cc;hp=9afe3853602e3cec3fe9d14264821e5a306f1908;hpb=a2b4b63a98cff9bbf979f446d0351d8978365518;p=melted diff --git a/src/modules/core/producer_noise.c b/src/modules/core/producer_noise.c index 9afe385..825f591 100644 --- a/src/modules/core/producer_noise.c +++ b/src/modules/core/producer_noise.c @@ -3,22 +3,22 @@ * Copyright (C) 2003-2004 Ushodaya Enterprises Limited * Author: Charles Yates * - * 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 library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. * - * This program is distributed in the hope that it will be useful, + * This library 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. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser 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. + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "producer_noise.h" +#include #include #include @@ -32,7 +32,7 @@ static unsigned int seed_x = 521288629; static unsigned int seed_y = 362436069; -static unsigned inline int fast_rand( ) +static inline unsigned int fast_rand( ) { static unsigned int a = 18000, b = 30903; seed_x = a * ( seed_x & 65535 ) + ( seed_x >> 16 ); @@ -42,11 +42,12 @@ static unsigned inline int fast_rand( ) // Foward declarations static int producer_get_frame( mlt_producer this, mlt_frame_ptr frame, int index ); +static void producer_close( mlt_producer this ); /** Initialise. */ -mlt_producer producer_noise_init( void *arg ) +mlt_producer producer_noise_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg ) { // Create a new producer object mlt_producer this = mlt_producer_new( ); @@ -56,6 +57,7 @@ mlt_producer producer_noise_init( void *arg ) { // Callback registration this->get_frame = producer_get_frame; + this->close = ( mlt_destructor )producer_close; } return this; @@ -64,7 +66,7 @@ mlt_producer producer_noise_init( void *arg ) static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_format *format, int *width, int *height, int writable ) { // Obtain properties of frame - mlt_properties properties = mlt_frame_properties( frame ); + mlt_properties properties = MLT_FRAME_PROPERTIES( frame ); // Calculate the size of the image int size = *width * *height * 2; @@ -104,7 +106,7 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form static int producer_get_audio( mlt_frame frame, int16_t **buffer, mlt_audio_format *format, int *frequency, int *channels, int *samples ) { // Get the frame properties - mlt_properties properties = mlt_frame_properties( frame ); + mlt_properties properties = MLT_FRAME_PROPERTIES( frame ); int size = 0; @@ -124,7 +126,7 @@ static int producer_get_audio( mlt_frame frame, int16_t **buffer, mlt_audio_form { int16_t *p = *buffer + size / 2; while ( p != *buffer ) - *( -- p ) = fast_rand( ) & 0xff; + *( -- p ) = fast_rand( ) & 0x0f00; } // Set the buffer for destruction @@ -136,16 +138,16 @@ static int producer_get_audio( mlt_frame frame, int16_t **buffer, mlt_audio_form static int producer_get_frame( mlt_producer this, mlt_frame_ptr frame, int index ) { // Generate a frame - *frame = mlt_frame_init( ); + *frame = mlt_frame_init( MLT_PRODUCER_SERVICE( this ) ); // Check that we created a frame and initialise it if ( *frame != NULL ) { // Obtain properties of frame - mlt_properties properties = mlt_frame_properties( *frame ); + mlt_properties properties = MLT_FRAME_PROPERTIES( *frame ); - // Aspect ratio is 1? - mlt_properties_set_double( properties, "aspect_ratio", 1.0 ); + // Aspect ratio is whatever it needs to be + mlt_properties_set_double( properties, "aspect_ratio", 0 ); // Set producer-specific frame properties mlt_properties_set_int( properties, "progressive", 1 ); @@ -157,7 +159,7 @@ static int producer_get_frame( mlt_producer this, mlt_frame_ptr frame, int index mlt_frame_push_get_image( *frame, producer_get_image ); // Specify the audio - ( *frame )->get_audio = producer_get_audio; + mlt_frame_push_audio( *frame, producer_get_audio ); } // Calculate the next timecode @@ -166,4 +168,10 @@ static int producer_get_frame( mlt_producer this, mlt_frame_ptr frame, int index return 0; } +static void producer_close( mlt_producer this ) +{ + this->close = NULL; + mlt_producer_close( this ); + free( this ); +}