]> git.sesse.net Git - vlc/blobdiff - modules/codec/tarkin.c
* include/vlc_common.h:
[vlc] / modules / codec / tarkin.c
index 373439989a8aa7f5550dfa6fe31cdd81884fe4f0..1c6b82c1e64837404ec6af25137ac52cbb10bce8 100644 (file)
@@ -2,7 +2,7 @@
  * tarkin.c: tarkin decoder module making use of libtarkin.
  *****************************************************************************
  * Copyright (C) 1999-2001 VideoLAN
- * $Id: tarkin.c,v 1.1 2002/11/18 13:28:09 gbazin Exp $
+ * $Id: tarkin.c,v 1.6 2003/10/25 00:49:13 sam Exp $
  *
  * Authors: Gildas Bazin <gbazin@netcourrier.com>
  *
@@ -10,7 +10,7 @@
  * 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
@@ -45,7 +45,7 @@
 #include <tarkin.h>
 
 /*****************************************************************************
- * dec_thread_t : vorbis decoder thread descriptor
+ * dec_thread_t : tarkin decoder thread descriptor
  *****************************************************************************/
 typedef struct dec_thread_t
 {
@@ -59,10 +59,8 @@ typedef struct dec_thread_t
      */
     TarkinStream *tarkin_stream;
 
-    TarkinInfo       ti; /* struct that stores all the static tarkin bitstream
-                            settings */
-    TarkinComment    tc; /* struct that stores all the bitstream user
-                          * comments */
+    TarkinInfo       ti;                        /* tarkin bitstream settings */
+    TarkinComment    tc;                   /* tarkin bitstream user comments */
     TarkinTime           tarkdate;
 
     /*
@@ -88,8 +86,8 @@ static void CloseDecoder ( dec_thread_t * );
 static void DecodePacket ( dec_thread_t * );
 static int  GetOggPacket ( dec_thread_t *, ogg_packet *, mtime_t * );
 
-static void tarkin_CopyPicture( dec_thread_t *, picture_t *, uint8_t * );
-static vout_thread_t *tarkin_SpawnVout( dec_thread_t *, int, int, int, int );
+static void tarkin_CopyPicture( dec_thread_t *, picture_t *, uint8_t *, int );
+
 /*****************************************************************************
  * Module descriptor
  *****************************************************************************/
@@ -97,6 +95,7 @@ vlc_module_begin();
     set_description( _("Tarkin decoder module") );
     set_capability( "decoder", 100 );
     set_callbacks( OpenDecoder, NULL );
+    add_shortcut( "tarkin" );
 vlc_module_end();
 
 /*****************************************************************************
@@ -104,14 +103,14 @@ vlc_module_end();
  *****************************************************************************/
 static int OpenDecoder( vlc_object_t *p_this )
 {
-    decoder_fifo_t *p_fifo = (decoder_fifo_t*) p_this;
+    decoder_t *p_dec = (decoder_t*)p_this;
 
-    if( p_fifo->i_fourcc != VLC_FOURCC('t','a','r','k') )
+    if( p_dec->p_fifo->i_fourcc != VLC_FOURCC('t','a','r','k') )
     {
         return VLC_EGENERIC;
     }
 
-    p_fifo->pf_run = RunDecoder;
+    p_dec->pf_run = RunDecoder;
     return VLC_SUCCESS;
 }
 
@@ -136,6 +135,7 @@ static int RunDecoder( decoder_fifo_t *p_fifo )
     memset( p_dec, 0, sizeof(dec_thread_t) );
     p_dec->p_fifo = p_fifo;
     p_dec->p_pes  = NULL;
+    p_dec->p_vout = NULL;
 
     /* Take care of the initial Tarkin header */
     p_dec->tarkin_stream = tarkin_stream_new();
@@ -149,7 +149,7 @@ static int RunDecoder( decoder_fifo_t *p_fifo )
     if( tarkin_synthesis_headerin( &p_dec->ti, &p_dec->tc, &oggpacket ) < 0 )
     {
         msg_Err( p_dec->p_fifo, "This bitstream does not contain Tarkin "
-                 "vido data");
+                 "video data");
         goto error;
     }
 
@@ -177,13 +177,13 @@ static int RunDecoder( decoder_fifo_t *p_fifo )
     /* Initialize the tarkin decoder */
     tarkin_synthesis_init( p_dec->tarkin_stream, &p_dec->ti );
 
-    /* vorbis decoder thread's main loop */
+    /* tarkin decoder thread's main loop */
     while( (!p_dec->p_fifo->b_die) && (!p_dec->p_fifo->b_error) )
     {
         DecodePacket( p_dec );
     }
 
-    /* If b_error is set, the vorbis decoder thread enters the error loop */
+    /* If b_error is set, the tarkin decoder thread enters the error loop */
     if( p_dec->p_fifo->b_error )
     {
         DecoderError( p_dec->p_fifo );
@@ -216,8 +216,7 @@ static void DecodePacket( dec_thread_t *p_dec )
     ogg_packet oggpacket;
     picture_t *p_pic;
     mtime_t i_pts;
-    int i_width, i_height, i_chroma, i_aspect;
-    uint32_t frame = 0;
+    int i_width, i_height, i_chroma, i_stride, i_aspect;
     uint8_t *rgb;
 
     if( GetOggPacket( p_dec, &oggpacket, &i_pts ) != VLC_SUCCESS )
@@ -229,29 +228,34 @@ static void DecodePacket( dec_thread_t *p_dec )
     tarkin_synthesis_packetin( p_dec->tarkin_stream, &oggpacket );
 
     while( tarkin_synthesis_frameout( p_dec->tarkin_stream,
-                                     &rgb, 0, &p_dec->tarkdate ) == 0 )
+                                      &rgb, 0, &p_dec->tarkdate ) == 0 )
     {
 
-       i_width = p_dec->tarkin_stream->layer->desc.width;
-       i_height = p_dec->tarkin_stream->layer->desc.height;
-       switch( p_dec->tarkin_stream->layer->desc.format )
-       {
-       case TARKIN_RGB24:
+        i_width = p_dec->tarkin_stream->layer->desc.width;
+        i_height = p_dec->tarkin_stream->layer->desc.height;
+        switch( p_dec->tarkin_stream->layer->desc.format )
+        {
+        case TARKIN_RGB24:
+            /*i_chroma = VLC_FOURCC('R','G','B','A');*/
             i_chroma = VLC_FOURCC('R','V','2','4');
-           break;
-       case TARKIN_RGB32:
+            i_stride = i_width * 3;
+            break;
+        case TARKIN_RGB32:
             i_chroma = VLC_FOURCC('R','V','3','2');
-           break;
-       case TARKIN_RGBA:
+            i_stride = i_width * 4;
+            break;
+        case TARKIN_RGBA:
             i_chroma = VLC_FOURCC('R','G','B','A');
-           break;
-       default:
+            i_stride = i_width * 4;
+            break;
+        default:
             i_chroma = VLC_FOURCC('Y','V','1','2');
-           break;
-       }
+            i_stride = i_width;
+            break;
+        }
         i_aspect = VOUT_ASPECT_FACTOR * i_width / i_height;
-        p_dec->p_vout = tarkin_SpawnVout( p_dec, i_width, i_height,
-                                         i_aspect, i_chroma );
+        p_dec->p_vout = vout_Request( p_dec->p_fifo, p_dec->p_vout,
+                                      i_width, i_height, i_chroma, i_aspect );
 
         /* Get a new picture */
         while( !(p_pic = vout_CreatePicture( p_dec->p_vout, 0, 0, 0 ) ) )
@@ -265,7 +269,7 @@ static void DecodePacket( dec_thread_t *p_dec )
         if( !p_pic )
             break;
 
-        tarkin_CopyPicture( p_dec, p_pic, rgb );
+        tarkin_CopyPicture( p_dec, p_pic, rgb, i_stride );
 
         tarkin_synthesis_freeframe( p_dec->tarkin_stream, rgb );
 
@@ -313,101 +317,38 @@ static void CloseDecoder( dec_thread_t * p_dec )
         if( p_dec->p_pes )
             input_DeletePES( p_dec->p_fifo->p_packets_mgt, p_dec->p_pes );
 
-        if( p_dec->p_vout )
-       {
-            vlc_object_detach( p_dec->p_vout );
-            vout_DestroyThread( p_dec->p_vout );
-       }
+        vout_Request( p_dec->p_fifo, p_dec->p_vout, 0, 0, 0, 0 );
 
-       if( p_dec->tarkin_stream )
-           tarkin_stream_destroy( p_dec->tarkin_stream );
+        if( p_dec->tarkin_stream )
+            tarkin_stream_destroy( p_dec->tarkin_stream );
 
         free( p_dec );
     }
 }
 
-/*****************************************************************************
- * tarkin_SpawnVout: creates a new video output
- *****************************************************************************/
-static vout_thread_t *tarkin_SpawnVout( dec_thread_t *p_dec,
-                                        int i_width,
-                                        int i_height,
-                                        int i_aspect,
-                                        int i_chroma )
-{
-    vout_thread_t *p_vout;
-
-    if( !i_width || !i_height )
-        return NULL;
-
-    if( !i_chroma )
-        return NULL;
-
-    /* Spawn a video output if there is none. First we look for our children,
-     * then we look for any other vout that might be available. */
-    p_vout = vlc_object_find( p_dec->p_fifo, VLC_OBJECT_VOUT,
-                                              FIND_CHILD );
-    if( !p_vout )
-    {
-        p_vout = vlc_object_find( p_dec->p_fifo, VLC_OBJECT_VOUT,
-                                                  FIND_ANYWHERE );
-    }
-
-    if( p_vout )
-    {
-        if( p_vout->render.i_width != i_width
-            || p_vout->render.i_height != i_height
-            || p_vout->render.i_chroma != i_chroma
-            || p_vout->render.i_aspect != i_aspect )
-        {
-            /* We are not interested in this format, close this vout */
-            vlc_object_detach( p_vout );
-            vlc_object_release( p_vout );
-            vout_DestroyThread( p_vout );
-            p_vout = NULL;
-        }
-        else
-        {
-            /* This video output is cool! Hijack it. */
-            vlc_object_detach( p_vout );
-            vlc_object_attach( p_vout, p_dec->p_fifo );
-            vlc_object_release( p_vout );
-        }
-    }
-
-    if( p_vout == NULL )
-    {
-        msg_Dbg( p_dec->p_fifo, "no vout present, spawning one" );
-
-        p_vout = vout_CreateThread( p_dec->p_fifo,
-                                    i_width, i_height,
-                                    i_chroma, i_aspect );
-    }
-
-    return( p_vout );
-}
-
 /*****************************************************************************
  * tarkin_CopyPicture: copy a picture from tarkin internal buffers to a
  *                     picture_t structure.
  *****************************************************************************/
 static void tarkin_CopyPicture( dec_thread_t *p_dec, picture_t *p_pic,
-                               uint8_t *p_src )
+                                uint8_t *p_src, int i_pitch )
 {
-    int i_plane, i_line, i_width, i_dst_stride;
-    u *p_dst;
+    int i_plane, i_line, i_src_stride, i_dst_stride;
+    uint8_t *p_dst;
 
     for( i_plane = 0; i_plane < p_pic->i_planes; i_plane++ )
     {
-       p_dst = p_pic->p[i_plane].p_pixels;
-       i_width = p_pic->p[i_plane].i_visible_pitch;
-       i_dst_stride = p_pic->p[i_plane].i_pitch;
-
-       for( i_line = 0; i_line < p_pic->p[i_plane].i_lines; i_line++ )
-       {
-           p_dec->p_fifo->p_vlc->pf_memcpy( p_dst, p_src, i_width );
-           p_src += i_width;
-           p_dst += i_dst_stride;
-       }
+        p_dst = p_pic->p[i_plane].p_pixels;
+        i_dst_stride = p_pic->p[i_plane].i_pitch;
+        i_src_stride = i_pitch;
+
+        for( i_line = 0; i_line < p_pic->p[i_plane].i_lines; i_line++ )
+        {
+            p_dec->p_fifo->p_vlc->pf_memcpy( p_dst, p_src,
+                                             i_src_stride );
+
+            p_src += i_src_stride;
+            p_dst += i_dst_stride;
+        }
     }
 }