Author: rolf
Date: 2008-01-11 05:04:50 -0500 (Fri, 11 Jan 2008)
New Revision: 92656

Modified:
   trunk/moon/src/ChangeLog
   trunk/moon/src/asf/ChangeLog
   trunk/moon/src/asf/asf-ffmpeg.h
   trunk/moon/src/asf/asf.cpp
   trunk/moon/src/mplayer2.cpp
   trunk/moon/src/pipeline-ffmpeg.cpp
   trunk/moon/src/pipeline-ffmpeg.h
   trunk/moon/src/pipeline.cpp
   trunk/moon/src/pipeline.h
Log:
* src/asf/asf-ffmpeg.h: Fix warning.
* src/mplayer2.cpp, src/pipeline.cpp, src/pipeline.h,
  src/pipeline-ffmpeg.cpp, src/pipeline-ffmpeg.h: Code-cleanup.
* src/asf/asf.cpp: If stream number is 0, don't try to handle it as a
  script command.

Modified: trunk/moon/src/ChangeLog
===================================================================
--- trunk/moon/src/ChangeLog    2008-01-11 10:00:42 UTC (rev 92655)
+++ trunk/moon/src/ChangeLog    2008-01-11 10:04:50 UTC (rev 92656)
@@ -1,3 +1,8 @@
+2008-01-11  Rolf Bjarne Kvinge <[EMAIL PROTECTED]> 
+
+       * mplayer2.cpp, pipeline.cpp, pipeline.h, pipeline-ffmpeg.cpp,
+         pipeline-ffmpeg.h: Code-cleanup.
+
 2008-01-10  Larry Ewing  <[EMAIL PROTECTED]>
 
        * runtime.cpp (Surface::InitializeDrawingArea): realize the widget

Modified: trunk/moon/src/asf/ChangeLog
===================================================================
--- trunk/moon/src/asf/ChangeLog        2008-01-11 10:00:42 UTC (rev 92655)
+++ trunk/moon/src/asf/ChangeLog        2008-01-11 10:04:50 UTC (rev 92656)
@@ -1,3 +1,9 @@
+2008-01-11  Rolf Bjarne Kvinge <[EMAIL PROTECTED]> 
+
+       * asf-ffmpeg.h: Fix warning.
+       * asf.cpp: If stream number is 0, don't try to handle it as a script
+         command.
+
 2008-01-10  Rolf Bjarne Kvinge <[EMAIL PROTECTED]> 
 
        * asf.cpp, asf.h: ASFParser::ReadPacket: don't seek if we don't have to.

Modified: trunk/moon/src/asf/asf-ffmpeg.h
===================================================================
--- trunk/moon/src/asf/asf-ffmpeg.h     2008-01-11 10:00:42 UTC (rev 92655)
+++ trunk/moon/src/asf/asf-ffmpeg.h     2008-01-11 10:04:50 UTC (rev 92656)
@@ -173,4 +173,4 @@
 
 #endif
 
-#endif // INCLUDE_FFMPEG
\ No newline at end of file
+#endif // INCLUDE_FFMPEG

Modified: trunk/moon/src/asf/asf.cpp
===================================================================
--- trunk/moon/src/asf/asf.cpp  2008-01-11 10:00:42 UTC (rev 92655)
+++ trunk/moon/src/asf/asf.cpp  2008-01-11 10:04:50 UTC (rev 92656)
@@ -971,9 +971,14 @@
        dump_int_data (payloads [0]->payload_data, payloads 
[0]->payload_data_length, 4);
        printf ("\n");
 */
+//     printf ("ASFFrameReader::Advance (): frame data: size = %.4lld, key = 
%s, pts = %.5llu, stream# = %i, media_object_number = %.3u, 
script_command_stream_index = %u (advanced).\n", 
+//             size, IsKeyFrame () ? "true " : "false", Pts (), StreamNumber 
(), media_object_number, script_command_stream_index);
+
+
        // Check if the current frame is a script command, in which case we 
must call the callback set in 
        // the parser (and read another frame).
-       if (StreamNumber () == script_command_stream_index) {
+       if (StreamNumber () == script_command_stream_index && 
script_command_stream_index > 0) {
+               printf ("reading script command\n");
                ReadScriptCommand ();
                goto start;
        }

Modified: trunk/moon/src/mplayer2.cpp
===================================================================
--- trunk/moon/src/mplayer2.cpp 2008-01-11 10:00:42 UTC (rev 92655)
+++ trunk/moon/src/mplayer2.cpp 2008-01-11 10:04:50 UTC (rev 92656)
@@ -294,13 +294,16 @@
        MediaFrame* frame = closure->frame;
        IMediaStream* stream = frame->stream;
        
+       if (closure->frame == NULL || closure->frame->pts == 0)
+               return MEDIA_SUCCESS;
+       
        closure->frame = NULL;
        
        switch (stream->GetType ()) {
-       case MEDIA_VIDEO: // TODO: Add locking here.
+       case MediaTypeVideo: // TODO: Add locking here.
                player->video->queue->Push (new Packet (frame));
                return MEDIA_SUCCESS;
-       case MEDIA_AUDIO: // TODO: Add locking here.
+       case MediaTypeAudio: // TODO: Add locking here.
                player->audio->queue->Push (new Packet (frame));
                return MEDIA_SUCCESS;
        default:
@@ -355,7 +358,7 @@
                        continue; // No encoding was found for the stream.
                
                switch (stream->GetType ()) {
-               case MEDIA_AUDIO:
+               case MediaTypeAudio:
                        audio->stream_count++;
                        
                        audio->stream = (AudioStream*) stream;
@@ -368,7 +371,7 @@
                                printf ("audio start pts is invalid? %lld\n", 
stream->start_time);
                        printf ("audio initial_pts = %lld\n", 
audio->initial_pts);
                        break;
-               case MEDIA_VIDEO: 
+               case MediaTypeVideo: 
                        video->media = media;
                        video->stream = (VideoStream*) stream;
                        
@@ -432,6 +435,7 @@
                audio->pts_per_frame = (buf_size * 2 * 2) / 
(audio->stream->sample_rate / 100);
                
                target_pts = audio->initial_pts;
+               printf ("initial pts (according to audio): %lld\n", target_pts);
        }
        
        if (video->stream != NULL) {//_id != -1) 
@@ -441,6 +445,7 @@
                media->GetNextFrameAsync (video->stream);
                
                target_pts = video->initial_pts;
+               printf ("initial pts (according to video): %lld\n", target_pts);
        }
        
        return true;
@@ -518,67 +523,14 @@
                frame->uncompressed_data_stride[2] == NULL)
                return;
        
+//     printf ("converting %p, %p, %p, %p, %p\n", 
frame->uncompressed_data_stride, frame->uncompressed_data_stride [0],
+//      frame->uncompressed_data_stride [1], frame->uncompressed_data_stride 
[2], frame->uncompressed_data_stride [3]);
+       
        video->stream->converter->Convert (frame->uncompressed_data_stride, 
frame->srcStride, frame->srcSlideY, frame->srcSlideH, rgb_dest, rgb_stride);
 
 }
 
-#define LOG_ADVANCE_AUDIO_FRAME1(x)// printf (x);
-#define LOG_ADVANCE_AUDIO_FRAME(x, ...)// printf (x, __VA_ARGS__);
-
 bool
-media_player_advance_audio_frame (MediaPlayer* mplayer)
-{
-       LOG_ADVANCE_AUDIO_FRAME1 ("media_player_advance_audio_frame ()\n");
-       Audio *audio = mplayer->audio;
-       struct pollfd *ufds = audio->ufds;
-       uint64_t frame_pts;
-       Packet *pkt;
-       bool play;
-       int nfds = audio->nfds;
-       
-       if (!mplayer->stop) {
-               if (mplayer->paused) {
-                       LOG_ADVANCE_AUDIO_FRAME1 
("media_player_advance_audio_frame called when player is paused.\n");
-                       return false; 
-               }
-               
-               play = mplayer->target_pts >= mplayer->seek_pts;
-       
-               LOG_ADVANCE_AUDIO_FRAME ("media_player_advance_audio_frame (), 
play: %s.\n", play ? "true" : "false");
-               if ((frame_pts = audio_play (audio, play, ufds, nfds)) > 0) {
-                       LOG_ADVANCE_AUDIO_FRAME 
("media_player_advance_audio_frame (): calculating pts, target_pts: %lld, 
frame_pts: %lld\n", mplayer->target_pts, frame_pts);
-                       // calculated pts
-                       //printf ("frame_pts = %llu\n", frame_pts);
-                       //pthread_mutex_lock (&mplayer->target_pts_lock);
-                       mplayer->target_pts += frame_pts;
-                       //pthread_mutex_unlock (&mplayer->target_pts_lock);
-                       //printf ("calculated target_pts = %llu\n", 
mplayer->target_pts);
-               } else {
-                       // decode an audio packet
-                       if (!audio->pkt && (pkt = (Packet *) audio->queue->Pop 
())) {
-                               LOG_ADVANCE_AUDIO_FRAME 
("media_player_advance_audio_frame (): calculating pts, target_pts: %lld, 
frame_pts: %lld\n", mplayer->target_pts, frame_pts);
-                               audio->inleft = pkt->size;
-                               audio->inptr = pkt->data;
-                               audio->pkt = pkt;
-                               
-                               //pthread_mutex_lock 
(&mplayer->target_pts_lock);
-                               mplayer->target_pts = pkt->pts;
-                               //pthread_mutex_unlock 
(&mplayer->target_pts_lock);
-                               //printf ("setting target_pts to %llu\n", 
mplayer->target_pts);
-                               audio->media->GetNextFrameAsync (audio->stream);
-                       }
-                       
-                       if (audio->pkt && audio_decode (audio)) {
-                               delete audio->pkt;
-                               audio->pkt = NULL;
-                       }
-               }
-       }
-               
-       return NULL;
-}
-
-bool
 MediaPlayer::AdvanceFrame ()
 {
        //printf ("MediaPlayer::AdvanceFrame ()\n");
@@ -594,8 +546,6 @@
                return false;
        }
        
-               //if (audio->stream != NULL)
-               //      media_player_advance_audio_frame (this);
        if (audio->stream == NULL) {
                // no audio to sync to
                uint64_t now = TimeManager::Instance()->GetCurrentTimeUsec();
@@ -620,11 +570,12 @@
        //      // use target_pts as set by audio thread
        //      pthread_mutex_lock (&target_pts_lock);
                target_pts = this->target_pts;
+               //printf ("AdvanceFrame (), syncing to audio, target_pts: 
%lld\n", target_pts);
        //      pthread_mutex_unlock (&target_pts_lock);
        }
        
        if (current_pts >= seek_pts && current_pts >= target_pts) {
-               //printf ("MediaPlayer::AdvanceFrame () we're ahead of playback 
(current_pts = %lld, seek_pts = %lld, target_pts = %lld).\n", current_pts, 
seek_pts, target_pts);
+               printf ("MediaPlayer::AdvanceFrame () we're ahead of playback 
(current_pts = %lld, seek_pts = %lld, target_pts = %lld).\n", current_pts, 
seek_pts, target_pts);
                return !eof;
        }
        
@@ -636,8 +587,8 @@
                //printf ("MediaPlayer::AdvanceFrame (): nothing in the 
list.\n");
        }
        
-       //int count = list->Length ();
-       //int dropped = 0;
+       int count = list->Length ();
+       int dropped = 0;
        
        if ((pkt = (Packet *) list->First ())) {
                do {
@@ -653,8 +604,11 @@
                        npkt = (Packet *) pkt->next;
                        
                        current_pts = pkt->pts;
+                       //printf ("MediaPlayer::AdvanceFrame (): got video 
frame with pts %lld, frame->pts = %lld, queue length: %i\n", pkt->pts, 
pkt->frame->pts, list->Length ());
                        list->Unlink (pkt);
                        
+                       //printf ("MediaPlayer::AdvanceFrame (): got video 
frame with pts %lld, frame->pts = %lld, queue length: %i\n", pkt->pts, 
pkt->frame->pts, list->Length ());
+                       
                        if (current_pts >= target_pts) {
                                // we are in sync (or ahead) of audio playback
                                //printf ("MediaPlayer::AdvanceFrame () we are 
in sync (or ahead) of audio playback (current_pts = %lld, seek_pts = %lld, 
target_pts = %lld).\n", current_pts, seek_pts, target_pts);
@@ -669,11 +623,10 @@
                        
                        delete pkt;
                        video->media->GetNextFrameAsync (video->stream); // 
Request another frame
-                       //dropped++;
+                       dropped++;
                        
                        // we are lagging behind, drop this frame
                        //printf ("MediaPlayer::AdvanceFrame () we are lagging 
behind, drop this frame (current_pts = %lld, seek_pts = %lld, target_pts = 
%lld).\n", current_pts, seek_pts, target_pts);
-                       //av_free (frame);
                        frame = NULL;
                        
                        pkt = npkt;
@@ -683,7 +636,7 @@
        video->queue->Unlock ();
        
        if (update) {
-               //printf ("MediaPlayer::AdvanceFrame () (%i items in list, %i 
dropped) copying %i bytes to rgb buffer for current_pts = %lld (target_pts = 
%lld), diff = %lld.\n", count, dropped, pkt->size, current_pts, target_pts, 
target_pts - pkt->pts);
+               printf ("MediaPlayer::AdvanceFrame () (%i items in list, %i 
dropped) copying %i bytes to rgb buffer for current_pts = %lld (target_pts = 
%lld, pkt->pts = %lld), diff = %lld.\n", count, dropped, pkt->size, 
current_pts, target_pts, pkt->pts, target_pts - pkt->pts);
                convert_to_rgb (video, pkt->frame);
                //memcpy (video->rgb_buffer, pkt->data, pkt->size);
                video->media->GetNextFrameAsync (video->stream);
@@ -693,6 +646,16 @@
                video->media->GetNextFrameAsync (video->stream);
                video->media->GetNextFrameAsync (video->stream);
                video->media->GetNextFrameAsync (video->stream);
+               video->media->GetNextFrameAsync (video->stream);
+               video->media->GetNextFrameAsync (video->stream);
+               video->media->GetNextFrameAsync (video->stream);
+               video->media->GetNextFrameAsync (video->stream);
+               video->media->GetNextFrameAsync (video->stream);
+               video->media->GetNextFrameAsync (video->stream);
+               video->media->GetNextFrameAsync (video->stream);
+               video->media->GetNextFrameAsync (video->stream);
+               video->media->GetNextFrameAsync (video->stream);
+               video->media->GetNextFrameAsync (video->stream);
                delete pkt;
                return true;
        }
@@ -1322,12 +1285,14 @@
        
        while (!mplayer->stop) {
                if (mplayer->paused) {
+                       printf ("audio_loop (): paused.\n");
                        // allow main thread to take pause lock
                        pthread_cond_signal (&mplayer->pause_cond);
                        pthread_mutex_unlock (&mplayer->pause_mutex);
                        
                        // wait for main thread to relinquish pause lock
                        pthread_cond_wait (&mplayer->pause_cond, 
&mplayer->pause_mutex);
+                       printf ("audio_loop (): resumed.\n");
                        continue;
                }
                
@@ -1339,7 +1304,7 @@
                        pthread_mutex_lock (&mplayer->target_pts_lock);
                        mplayer->target_pts += frame_pts;
                        pthread_mutex_unlock (&mplayer->target_pts_lock);
-                       //printf ("calculated target_pts = %llu\n", 
mplayer->target_pts);
+                       //printf ("calculated target_pts = %llu (frame_pts: 
%lld)\n", mplayer->target_pts, frame_pts);
                } else {
                        // decode an audio packet
                        if (!audio->pkt && (pkt = (Packet *) audio->queue->Pop 
())) {
@@ -1350,7 +1315,7 @@
                                pthread_mutex_lock (&mplayer->target_pts_lock);
                                mplayer->target_pts = pkt->pts;
                                pthread_mutex_unlock 
(&mplayer->target_pts_lock);
-                               //printf ("setting target_pts to %llu\n", 
mplayer->target_pts);
+                               printf ("setting target_pts to %llu\n", 
mplayer->target_pts);
                                audio->media->GetNextFrameAsync (audio->stream);
                                //printf ("audio_loop, popped a packet, %i 
packets left. inleft: %i, inptr: %p\n", audio->queue->Length (), audio->inleft, 
audio->inptr);
                                
@@ -1364,6 +1329,8 @@
                }
        }
        
+       printf ("audio_loop (): exited.\n");
+       
        pthread_mutex_unlock (&mplayer->pause_mutex);
        
        g_free (ufds);

Modified: trunk/moon/src/pipeline-ffmpeg.cpp
===================================================================
--- trunk/moon/src/pipeline-ffmpeg.cpp  2008-01-11 10:00:42 UTC (rev 92655)
+++ trunk/moon/src/pipeline-ffmpeg.cpp  2008-01-11 10:04:50 UTC (rev 92656)
@@ -43,8 +43,6 @@
                return;
        
        avcodec_init ();
-       
-       //av_register_all ();
        avcodec_register_all ();
                
        ffmpeg_initialized = true;
@@ -72,11 +70,11 @@
        int ffmpeg_result = 0;
        AVCodec *codec = NULL;
        
-       printf ("FfmpegDecoder::Open ().\n");
+       //printf ("FfmpegDecoder::Open ().\n");
        
        codec = avcodec_find_decoder_by_name (stream->codec);
        
-       printf ("FfmpegDecoder::Open (): Found codec: %p (id: '%s')\n", codec, 
stream->codec);
+       //printf ("FfmpegDecoder::Open (): Found codec: %p (id: '%s')\n", 
codec, stream->codec);
        
        if (codec == NULL) {
                result = MEDIA_UNKNOWN_CODEC;
@@ -93,7 +91,7 @@
        }
        
        if (stream->extra_data_size > 0) {
-               printf ("FfmpegDecoder::Open (): Found %i bytes of extra 
data.\n", stream->extra_data_size);
+               //printf ("FfmpegDecoder::Open (): Found %i bytes of extra 
data.\n", stream->extra_data_size);
                context->extradata_size = stream->extra_data_size;
                context->extradata = (uint8_t*) av_mallocz 
(stream->extra_data_size + FF_INPUT_BUFFER_PADDING_SIZE + 100);
                if (context->extradata == NULL) {
@@ -104,11 +102,11 @@
                memcpy (context->extradata, stream->extra_data, 
stream->extra_data_size);
        }
 
-       if (stream->GetType () == MEDIA_VIDEO) {
+       if (stream->GetType () == MediaTypeVideo) {
                VideoStream *vs = (VideoStream*) stream;
                context->width = vs->width;
                context->height = vs->height;
-       } else if (stream->GetType () == MEDIA_AUDIO) {
+       } else if (stream->GetType () == MediaTypeAudio) {
                AudioStream *as = (AudioStream*) stream;
                context->sample_rate = as->sample_rate;
                context->channels = as->channels;
@@ -129,7 +127,7 @@
        
        pixel_format = FfmpegConverter::ToMoonPixFmt (context->pix_fmt);
                
-       printf ("FfmpegDecoder::Open (): Opened codec successfully.\n");
+       //printf ("FfmpegDecoder::Open (): Opened codec successfully.\n");
        
        return result;
        
@@ -174,7 +172,7 @@
        //media_frame->printf ();
        //printf ("\n");
        
-       if (stream->GetType () == MEDIA_VIDEO) {
+       if (stream->GetType () == MediaTypeVideo) {
                VideoStream* vs = (VideoStream*) stream;
                
                frame = avcodec_alloc_frame ();
@@ -201,33 +199,15 @@
                        }
                        media_frame->srcSlideY = 0;
                        media_frame->srcSlideH = context->height;
-                       
-                       //if (frame->data == NULL || frame->data[1] == NULL || 
frame->data[2] == NULL)
-                       //      return;
-                       /*
-                       struct SwsContext *scaler;
-                       scaler = sws_getContext (context->width, 
context->height, context->pix_fmt,
-                                       context->width, context->height, 
PIX_FMT_RGB32,
-                                       SWS_BICUBIC, NULL, NULL, NULL);
-                       sws_scale (scaler, frame->data, frame->linesize, 0,
-                                  context->height, rgb_dest, rgb_stride);
-                       sws_freeContext (scaler);
-                       */
-                       //vs->converter->Convert (frame->data, frame->linesize, 
0, context->height, rgb_dest, rgb_stride);
-                       //vs->converter->Convert 
(media_frame->uncompressed_data_stride, media_frame->srcStride, 
media_frame->srcSlideY, media_frame->srcSlideH, rgb_dest, rgb_stride);
-                       //uint8_t start = *(uint8_t*) frame->data;
-                       //for (int i = 0; i < media_frame->uncompressed_size; 
i++) {
-                       //      ((uint8_t*) media_frame->uncompressed_data) [i] 
= start++;
-                       //}
+                        // We can't free the frame until the data has been 
used, 
+                        // so save the frame in decoder_specific_data. 
+                        // This will cause FfmpegDecoder::Cleanup to be called 
+                        // when the MediaFrame is deleted.
                        media_frame->decoder_specific_data = frame;
                } else {
-                       printf ("FfmpegDecoder::DecodeFrame (%p): didn't get 
picture (%i), length = %i.\n", media_frame, got_picture, length);
+                       //printf ("FfmpegDecoder::DecodeFrame (%p): didn't get 
picture (%i), length = %i.\n", media_frame, got_picture, length);
                }
-               
-               //av_free (frame);
-       
-       } else if (stream->GetType () == MEDIA_AUDIO) {
-//             printf ("Audio decoding not implemented yet.");
+       } else if (stream->GetType () == MediaTypeAudio) {
                int frame_size_ptr = AUDIO_BUFFER_SIZE;
                length = avcodec_decode_audio2 (context, (int16_t*) 
audio_buffer, &frame_size_ptr, (uint8_t*) media_frame->compressed_data, 
media_frame->compressed_size);
                //printf ("FfmpegDecoder::DecodeFrame (), length: %i, 
frame_size_ptr = %i\n", length, frame_size_ptr);
@@ -241,17 +221,8 @@
                        media_frame->uncompressed_size = frame_size_ptr;
                        media_frame->uncompressed_data = (uint8_t*) g_malloc 
(media_frame->uncompressed_size);
                        memcpy (media_frame->uncompressed_data, audio_buffer, 
media_frame->uncompressed_size);                  
-
-                       /*printf ("FfmpegDecoder::DecodeFrame (%p): got %i 
bytes of audio back (of %i bytes sent in):", media_frame, frame_size_ptr, 
media_frame->compressed_size);
-                       printf (" In:  ");
-                       dump_int_data (media_frame->compressed_data, 
media_frame->compressed_size, 4);
-                       //printf ("\n");
-                       printf (" Out: ");
-                       dump_int_data (media_frame->uncompressed_data, 
media_frame->uncompressed_size, 4);
-                       printf ("\n");
-                               */
                } else {
-                       printf ("FfmpegDecoder::DecodeFrame (%p): didn't get 
any audio back.\n", media_frame);
+                       //printf ("FfmpegDecoder::DecodeFrame (%p): didn't get 
any audio back.\n", media_frame);
                }
                
                if (length != media_frame->compressed_size) {
@@ -262,10 +233,8 @@
                return MEDIA_FAIL;
        }
        
-       //AVFrame_dump (frame, 1);
-       
-       
        return MEDIA_SUCCESS;
 }
 
 #endif // INCLUDE_FFMPEG
+

Modified: trunk/moon/src/pipeline-ffmpeg.h
===================================================================
--- trunk/moon/src/pipeline-ffmpeg.h    2008-01-11 10:00:42 UTC (rev 92655)
+++ trunk/moon/src/pipeline-ffmpeg.h    2008-01-11 10:04:50 UTC (rev 92656)
@@ -67,25 +67,25 @@
                }
        }
        
-       static PixelFormat ToFfmpegPixFmt (PIXEL_FORMAT format)
+       static PixelFormat ToFfmpegPixFmt (MoonPixelFormat format)
        {
                switch (format) {
-               case PIXEL_FORMAT_YUV420P: return PIX_FMT_YUV420P;  
-               case PIXEL_FORMAT_RGB32: return PIX_FMT_RGB32;
+               case MoonPixelFormatYUV420P: return PIX_FMT_YUV420P;  
+               case MoonPixelFormatRGB32: return PIX_FMT_RGB32;
                default:
                        printf ("FfmpegConverter::ToFfmpegPixFmt (%i): Unknown 
pixel format.\n", format);
                        return PIX_FMT_NONE;
                }
        }
        
-       static PIXEL_FORMAT ToMoonPixFmt (PixelFormat format)
+       static MoonPixelFormat ToMoonPixFmt (PixelFormat format)
        {
                switch (format) {
-               case PIX_FMT_YUV420P: return PIXEL_FORMAT_YUV420P;
-               case PIX_FMT_RGB32: return PIXEL_FORMAT_RGB32;
+               case PIX_FMT_YUV420P: return MoonPixelFormatYUV420P;
+               case PIX_FMT_RGB32: return MoonPixelFormatRGB32;
                default:
                        printf ("FfmpegConverter::ToMoonPixFmt (%i): Unknown 
pixel format.\n", format);
-                       return PIXEL_FORMAT_NONE;
+                       return MoonPixelFormatNone;
                };
        }
        

Modified: trunk/moon/src/pipeline.cpp
===================================================================
--- trunk/moon/src/pipeline.cpp 2008-01-11 10:00:42 UTC (rev 92655)
+++ trunk/moon/src/pipeline.cpp 2008-01-11 10:04:50 UTC (rev 92656)
@@ -197,12 +197,12 @@
                if (decoder != NULL) {
                        stream->SetDecoder (decoder);
                        
-                       if (stream->GetType () == MEDIA_VIDEO) {
+                       if (stream->GetType () == MediaTypeVideo) {
                                VideoStream* vs = (VideoStream*) stream;
                                IImageConverter* converter;
                                converter = new FfmpegConverter (this, vs);
                                converter->input_format = 
vs->decoder->pixel_format;
-                               converter->output_format = PIXEL_FORMAT_RGB32;
+                               converter->output_format = MoonPixelFormatRGB32;
                                if (MEDIA_SUCCEEDED (converter->Open ())) {
                                        // FIXME: What should happen if there's 
no available converter? No video?
                                        vs->converter = converter;
@@ -269,17 +269,17 @@
                if (queued_requests != NULL) {
                        // Find the first audio node
                        current = (Media::Node*) queued_requests->First ();
-                       while (current != NULL && current->stream->GetType () 
!= MEDIA_AUDIO) {
+                       while (current != NULL && current->stream->GetType () 
!= MediaTypeAudio) {
                                current = (Media::Node*) current->next;
                        }
-                       if (current != NULL && current->stream->GetType () == 
MEDIA_AUDIO) {
+                       if (current != NULL && current->stream->GetType () == 
MediaTypeAudio) {
                                node = current;
                        } else {
                                // No audio node, just get the first node
                                node = (Media::Node*) queued_requests->First ();
                        }
                        queued_requests->Unlink (node);
-                       printf ("Media::FrameReaderLoop (): got a %s node, 
there are %i nodes left.\n", node->stream->GetType () == MEDIA_AUDIO ? "audio" 
: (node->stream->GetType () == MEDIA_VIDEO ? "video" : "unknown") , 
queued_requests->Length ());
+                       LOG_FRAMEREADERLOOP ("Media::FrameReaderLoop (): got a 
%s node, there are %i nodes left.\n", node->stream->GetType () == 
MediaTypeAudio ? "audio" : (node->stream->GetType () == MediaTypeVideo ? 
"video" : "unknown") , queued_requests->Length ());
                }
                pthread_mutex_unlock (&queue_mutex);
                
@@ -715,17 +715,37 @@
 /*
  * MediaClosure
  */ 
- 
+
+MediaClosure::MediaClosure () : 
+       callback (NULL), frame (NULL), media (NULL), context (NULL)
+{
+}
+
 MediaClosure::~MediaClosure ()
 {
        delete frame;
        frame = NULL;
 }
 
+MediaResult
+MediaClosure::Call ()
+{
+       if (callback)
+               return callback (this);
+               
+       return MEDIA_NOCALLBACK;
+}
 /*
  * IMediaStream
  */
 
+IMediaStream::IMediaStream (Media* media) : 
+       extra_data (NULL), extra_data_size (NULL), codec_id (0), start_time (0),
+       msec_per_frame (0), duration (0), decoder (NULL), codec (NULL), 
min_padding (0),
+       index (-1), context (NULL)
+{
+}
+
 IMediaStream::~IMediaStream ()
 {
        delete decoder;
@@ -758,6 +778,17 @@
  * MediaFrame
  */ 
  
+MediaFrame::MediaFrame () : 
+       stream (NULL), decoder_specific_data (NULL), 
+       pts (0), duration (0), compressed_size (0), uncompressed_size (0),
+       compressed_data (NULL), uncompressed_data (NULL), srcSlideY (0), 
srcSlideH (0)
+{
+       for (int i = 0; i < 4; i++) {
+               uncompressed_data_stride [i] = 0;  
+               srcStride [i] = 0;
+       }
+}
+ 
 MediaFrame::~MediaFrame ()
 {
        g_free (compressed_data);
@@ -769,3 +800,79 @@
                stream->decoder->Cleanup (this);
        }
 }
+
+/*
+ * IMediaObject
+ */
+ 
+IMediaObject::IMediaObject (Media* med) : 
+       media (med), callback (NULL)
+{
+}
+
+IMediaObject::~IMediaObject ()
+{
+}
+
+/*
+ * IMediaSource
+ */
+
+/*
+ * IMediaDemuxer
+ */
+
+void
+IMediaDemuxer::SetStreams (IMediaStream** streams, int count)
+{
+       this->streams = streams;
+       this->stream_count = count;
+}
+
+/*
+ * IMediaDecoder
+ */
+
+IMediaDecoder::IMediaDecoder (Media* media, IMediaStream* stream)
+{
+       this->media = media;
+       this->stream = stream;
+}
+
+/*
+ * IImageConverter
+ */
+
+IImageConverter::IImageConverter (Media* med, VideoStream* str) : 
+       media (med), stream (str), input_format (MoonPixelFormatNone), 
output_format (MoonPixelFormatNone)
+{
+}
+
+/*
+ * VideoStream
+ */
+
+
+VideoStream::VideoStream (Media* media) : IMediaStream (media),
+       width (0), height (0), msec_per_frame (0), initial_pts (0),
+       bits_per_sample (0), converter (NULL)
+{
+}
+
+VideoStream::~VideoStream ()
+{
+       if (converter != NULL) {
+               delete converter;
+               converter = NULL;
+       }
+}
+
+/*
+ * MediaClosure
+ */
+
+
+
+
+}
+

Modified: trunk/moon/src/pipeline.h
===================================================================
--- trunk/moon/src/pipeline.h   2008-01-11 10:00:42 UTC (rev 92655)
+++ trunk/moon/src/pipeline.h   2008-01-11 10:04:50 UTC (rev 92656)
@@ -10,7 +10,7 @@
  * 
  */
 
-//#define MOON_MEDIA
+#define MOON_MEDIA
 
 #ifndef __MOON_PIPELINE_H_
 #define __MOON_PIPELINE_H_
@@ -114,24 +114,24 @@
 
 #define MEDIA_SUCCEEDED(x) ((x == 0))
 
-#define MEDIA_VIDEO 1
-#define MEDIA_AUDIO 2
-#define MEDIA_MARKER 3
+enum MoonPixelFormat {
+       MoonPixelFormatNone = 0,
+       MoonPixelFormatRGB32,
+       MoonPixelFormatYUV420P
+};
 
-typedef MediaResult MediaCallback (MediaClosure* closure);
-
-enum PIXEL_FORMAT {
-       PIXEL_FORMAT_NONE = 0,
-       PIXEL_FORMAT_RGB32 = 1,
-       PIXEL_FORMAT_YUV420P
+enum MoonMediaType {
+       MediaTypeNone = 0,
+       MediaTypeVideo,
+       MediaTypeAudio,
+       MediaTypeMarker
 };
 
+typedef MediaResult MediaCallback (MediaClosure* closure);
+
 class MediaClosure {
 public:
-       MediaClosure () : 
-               callback (NULL), frame (NULL), media (NULL), context (NULL)
-       {
-       }
+       MediaClosure ();
        ~MediaClosure ();
        
        MediaCallback* callback;
@@ -139,13 +139,9 @@
        Media* media;
        void* context;
        
-       MediaResult Call ()
-       {
-               if (callback)
-                       return callback (this);
-                       
-               return MEDIA_NOCALLBACK;
-       }
+       // Calls the callback and returns the callback's return value
+       // If no callback is set, returns MEDIA_NO_CALLBACK
+       MediaResult Call ();
 }; 
 
 class Media {
@@ -224,64 +220,40 @@
  
 class MediaFrame {
 public:
+       ~MediaFrame ();
+       MediaFrame ();
+       
        IMediaStream* stream;
        void* decoder_specific_data; // data specific to the decoder
        guint64 pts; // Set by the demuxer
        guint64 duration; // Set by the demuxer
-       //gint32 linesize; // ?
+
        guint32 compressed_size; // Set by the demuxer
        guint32 uncompressed_size; // Set by the decoder
 
        void* compressed_data; // Set by the demuxer
        void* uncompressed_data; // Set by the decoder
 
-       //int linesize [4];
-       guint8 *uncompressed_data_stride[4];
-       int srcSlideY;
-       int srcSlideH;
-       int srcStride [4];
+       guint8 *uncompressed_data_stride[4]; // Set by the decoder
+       int srcSlideY; // Set by the decoder
+       int srcSlideH; // Set by the decoder
+       int srcStride [4]; // Set by the decoder
        
-       void printf ()
-       {
-               //::printf ("pts = %llu, duration = %llu, linesize = %i, %i, 
%i, %i, compressed_size = %u, uncompressed_size = %u, compressed_data = %p, 
uncompressed_data = %p", 
-               //      pts, duration, linesize [0], linesize [1], linesize 
[2], linesize [3], compressed_size, uncompressed_size, compressed_data, 
uncompressed_data);
-               //dump_data (compressed_data, compressed_size);
-               //dump_data (uncompressed_data, uncompressed_size);
-       }
-       
-       ~MediaFrame ();
 };
 
 // Interfaces
 
 class IMediaObject {
 public:
-       IMediaObject (Media* med) : 
-               media (med), callback (NULL)
-       {
-       }
+       IMediaObject (Media* med);
+       virtual ~IMediaObject ();
        
-       Media* GetMedia () { return media; }
        //      Sets the callback to call when the frame is read
        void SetFrameReadCallback (MediaClosure* callback);
        
-       MediaResult ProcessFrame (MediaFrame* frame)
-       {
-               MediaResult result = ProcessFrameInternal (frame);
-               
-               if (!MEDIA_SUCCEEDED (result))
-                       return result;
-                       
-               if (callback)
-                       return callback->Call ();
-                       
-               return MEDIA_SUCCESS;
-       }
-       
-       
-       
+       Media* GetMedia () { return media; }
+
 protected:
-       virtual MediaResult ProcessFrameInternal (MediaFrame* frame) = 0;
        Media* media;
        
 private:
@@ -291,16 +263,11 @@
 
 class IMediaStream  {
 public:
-       IMediaStream (Media* media) : 
-               extra_data (NULL), extra_data_size (NULL), codec_id (0), 
start_time (0),
-               msec_per_frame (0), duration (0), decoder (NULL), codec (NULL), 
min_padding (0),
-               index (-1)
-       {
-       }
+       IMediaStream (Media* media);
        virtual ~IMediaStream ();
 
        //      Video, Audio, Markers, etc.
-       virtual int GetType () = 0; 
+       virtual MoonMediaType GetType () = 0; 
        IMediaDecoder* GetDecoder () { return decoder; }
        void SetDecoder (IMediaDecoder* dec) { decoder = dec; }
        //      If this stream is enabled (producing output). 
@@ -313,7 +280,6 @@
        void* GetContext () { return context; }
        void  SetContext (void* context) { this->context = context; }
        
-       
        void* extra_data;
        int extra_data_size;
        int codec_id;
@@ -329,10 +295,10 @@
        // 0-based index of the stream in the media
        // set by the demuxer, until then its value must be -1
        int index; 
+       
 private:
        bool enabled;
        void* context;
-       IMediaObject* first_object;
 };
 
 
@@ -370,15 +336,7 @@
        }
        
 protected:
-       void SetStreams (IMediaStream** streams, int count)
-       {
-               this->streams = streams;
-               this->stream_count = count;
-       }
-       virtual MediaResult ProcessFrameInternal (MediaFrame* frame)
-       {
-               return ReadFrame (frame);
-       }
+       void SetStreams (IMediaStream** streams, int count);
        
 private:
        int stream_count;
@@ -387,33 +345,25 @@
 
 class IMediaDecoder {
 public:
-       IMediaDecoder (Media* media, IMediaStream* stream)
-       {
-               this->media = media;
-               this->stream = stream;
-       }
+       IMediaDecoder (Media* media, IMediaStream* stream);
        virtual ~IMediaDecoder () {}
        
        virtual MediaResult DecodeFrame (MediaFrame* frame) = 0;
        virtual MediaResult Open () = 0;
-       virtual void Cleanup (MediaFrame* frame) {}
-       PIXEL_FORMAT pixel_format; // The pixel format this codec outputs.
+       virtual void Cleanup (MediaFrame* frame) {} // If 
MediaFrame->decoder_specific_data is non-NULL, this method is called in 
~MediaFrame.
+       
+       MoonPixelFormat pixel_format; // The pixel format this codec outputs. 
Open () should fill this in.
        IMediaStream* stream;
        Media* media;
-       
-protected:
-       virtual MediaResult ProcessFrameInternal (MediaFrame* frame)
-       {
-               return DecodeFrame (frame);
-       }
 };
 
+
+/*
+ * Inherit from this class to provide image converters (yuv->rgb for instance) 
+ */
 class IImageConverter {
 public:
-       IImageConverter (Media* med, VideoStream* str) : 
-               media (med), stream (str), input_format (PIXEL_FORMAT_NONE), 
output_format (PIXEL_FORMAT_NONE)
-       {
-       }
+       IImageConverter (Media* med, VideoStream* str);
        virtual ~IImageConverter () {}
        
        virtual MediaResult Open () = 0;
@@ -421,8 +371,8 @@
        
        Media* media;
        VideoStream* stream;
-       PIXEL_FORMAT input_format;
-       PIXEL_FORMAT output_format;
+       MoonPixelFormat input_format;
+       MoonPixelFormat output_format;
 };
 
 // Implementations
@@ -471,47 +421,14 @@
        virtual bool Eof () { return false; }
        
 };
- 
-class ASFDemuxer : public IMediaDemuxer {
-public:
-       ASFDemuxer (Media* media);
-       ~ASFDemuxer ();
-       
-       virtual MediaResult ReadHeader ();
-       virtual MediaResult ReadFrame (MediaFrame* frame);
-       
-private:
-       ASFParser* parser;
-       ASFFrameReader* reader;
-       gint32* stream_to_asf_index;
-};
- 
-class MSDecoder : public IMediaDecoder {
-public:
-       MSDecoder (Media* media, IMediaStream* stream) : IMediaDecoder (media, 
stream) {}
-       virtual MediaResult Open ()
-       {
-       return MEDIA_FAIL;
-       }
-};
 
 class VideoStream : public IMediaStream {
 public:
-       VideoStream (Media* media) : IMediaStream (media),
-               width (0), height (0), msec_per_frame (0), initial_pts (0),
-               bits_per_sample (0), converter (NULL)
-       {}
-       virtual ~VideoStream ()
-       {
-               if (converter != NULL) {
-                       delete converter;
-                       converter = NULL;
-               }
-       }
-    int GetOutputFormat ();
+       VideoStream (Media* media);
+       virtual ~VideoStream ();
+           
+       virtual MoonMediaType GetType () { return MediaTypeVideo; } 
     
-       virtual int GetType () { return MEDIA_VIDEO; } 
-    
     guint32 width;
     guint32 height;
     guint32 msec_per_frame;
@@ -524,19 +441,36 @@
 public:
        AudioStream (Media* media) : IMediaStream (media) {}
        
-    int GetOutputFormat ();
-       virtual int GetType () { return MEDIA_AUDIO; }
+       virtual MoonMediaType GetType () { return MediaTypeAudio; }
+       
        int channels;
        int sample_rate;
        int bit_rate;
        int block_align;
        int bits_per_sample;
 };
- 
+
+/*
+ * ASF related implementations
+ */
+class ASFDemuxer : public IMediaDemuxer {
+public:
+       ASFDemuxer (Media* media);
+       ~ASFDemuxer ();
+       
+       virtual MediaResult ReadHeader ();
+       virtual MediaResult ReadFrame (MediaFrame* frame);
+       
+private:
+       ASFParser* parser;
+       ASFFrameReader* reader;
+       gint32* stream_to_asf_index;
+};
+
 class ASFMarkerStream : public IMediaStream {
 public:
        ASFMarkerStream (Media* media) : IMediaStream (media) {}
-       virtual int GetType () { return MEDIA_MARKER; } 
+       virtual MoonMediaType GetType () { return MediaTypeMarker; } 
 };
 
 class ASFMarkerDecoder : public IMediaDecoder {
@@ -546,4 +480,30 @@
        virtual MediaResult Open () {return MEDIA_SUCCESS; }
 }; 
 
+/*
+ * Mp3 related implementations
+ */
+ 
+class Mp3Decoder : public IMediaDecoder {
+public:
+       Mp3Decoder (Media* media, IMediaStream* stream);
+       virtual ~Mp3Decoder ();
+       
+       virtual MediaResult DecodeFrame (MediaFrame* frame);
+       virtual MediaResult Open ();
+};
+
+/*
+ * MS related implementations
+ */
+
+class MSDecoder : public IMediaDecoder {
+public:
+       MSDecoder (Media* media, IMediaStream* stream) : IMediaDecoder (media, 
stream) {}
+       virtual MediaResult Open ()
+       {
+               return MEDIA_FAIL;
+       }
+};
+
 #endif

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to