]> git.sesse.net Git - vlc/blobdiff - modules/demux/playlist/gvp.c
shoutcast: Fix some leaks.
[vlc] / modules / demux / playlist / gvp.c
index fe3033a0fd761d489f9b760d0d0cd310ea2fd18b..59299d738b6e755df94acf3cb8f02746791ff4a8 100644 (file)
  * description:<desc linei>^M
  * description:<desc final line (no ^M)>
  * lines starting with # are comments
+ *
+ * Example:
+
+# download the free Google Video Player from http://video.google.com/
+gvp_version:1.1
+url:http://vp.video.google.com/videodownload?version=0&secureurl=uAAAAMVHt_Q99OwfGxlWVWH7jd6AA_3n4TboaxIELD_kCg3KcBPSxExZFvQv5DGAxrahVg57KZNZvd0EORPBM3xrxTJ3FdLEWBYiduklpviqjE1Q5zLAkiEZaUsUSFtmbBZDTUUBuN9moYY59eK8lpWXsgTbYB1tLVtaxNBpAMRMyVeHoiJ7BzYdENk-PqJeBbr50QbQ83WK87yJAbN2pSRnF-ucCuNMSLBV7wBL4IcxFpYb1WOK-YXkyxY0NtWlPBufTA&sigh=matNCEVSOR8c-3zN9Gtx0zGinwU&begin=0&len=59749&docid=-715862862672743260
+docid:-715862862672743260
+duration:59749
+title:Apple Macintosh 1984 Superbowl Commercial
+description:The now infamous Apple Macintosh commercial aired during the 1984 SuperBowl.
+
  */
 
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#include <vlc/vlc.h>
-#include <vlc/input.h>
-#include <vlc/intf.h>
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+#include <vlc_demux.h>
 
-#include <errno.h>                                                 /* ENOMEM */
 #include "playlist.h"
 
 #define MAX_LINE 1024
 
 struct demux_sys_t
 {
-    playlist_t *p_playlist;
-    playlist_item_t *p_current;
-    playlist_item_t *p_item_in_category;
-    int i_parent_id;
+    input_item_t *p_current_input;
 };
 
 /*****************************************************************************
@@ -63,22 +73,32 @@ static int Control( demux_t *p_demux, int i_query, va_list args );
 /*****************************************************************************
  * Import_GVP: main import function
  *****************************************************************************/
-int E_(Import_GVP)( vlc_object_t *p_this )
+int Import_GVP( vlc_object_t *p_this )
 {
     demux_t *p_demux = (demux_t *)p_this;
-    byte_t *p_peek;
+    int i_peek, i, b_found = false;
+    const uint8_t *p_peek;
+
+    i_peek = stream_Peek( p_demux->s, &p_peek, MAX_LINE );
 
-    CHECK_PEEK( p_peek, 12 );
-    if( !POKE( p_peek, "gvp_version:", 12 ) )
+    for( i = 0; i < i_peek - (int)sizeof("gvp_version:"); i++ )
     {
-        return VLC_EGENERIC;
+        if( p_peek[i] == 'g' && p_peek[i+1] == 'v' && p_peek[i+2] == 'p' &&
+            !memcmp( p_peek+i, "gvp_version:", sizeof("gvp_version:") - 1 ) )
+        {
+            b_found = true;
+            break;
+        }
     }
 
-    STANDARD_DEMUX_INIT_MSG(  "using Google Video Playlist (gvp) import" )
+    if( !b_found ) return VLC_EGENERIC;
+
+    STANDARD_DEMUX_INIT_MSG(  "using Google Video Playlist (gvp) import" );
     p_demux->pf_control = Control;
     p_demux->pf_demux = Demux;
-    MALLOC_ERR( p_demux->p_sys, demux_sys_t );
-    p_demux->p_sys->p_playlist = NULL;
+    p_demux->p_sys = malloc( sizeof( demux_sys_t ) );
+    if( !p_demux->p_sys )
+        return VLC_ENOMEM;
 
     return VLC_SUCCESS;
 }
@@ -86,13 +106,11 @@ int E_(Import_GVP)( vlc_object_t *p_this )
 /*****************************************************************************
  * Deactivate: frees unused data
  *****************************************************************************/
-void E_(Close_GVP)( vlc_object_t *p_this )
+void Close_GVP( vlc_object_t *p_this )
 {
     demux_t *p_demux = (demux_t *)p_this;
     demux_sys_t *p_sys = p_demux->p_sys;
 
-    if( p_sys->p_playlist )
-        vlc_object_release( p_sys->p_playlist );
     free( p_sys );
 }
 
@@ -109,13 +127,11 @@ static int Demux( demux_t *p_demux )
     int i_duration = -1;
     char *psz_title = NULL;
     char *psz_description = NULL;
+    input_item_t *p_input;
 
-    INIT_PLAYLIST_STUFF;
+    input_item_t *p_current_input = GetCurrentItem(p_demux);
 
-    p_sys->p_playlist = p_playlist;
-    p_sys->p_current = p_current;
-    p_sys->i_parent_id = i_parent_id;
-    p_sys->p_item_in_category = p_item_in_category;
+    p_sys->p_current_input = p_current_input;
 
     while( ( psz_line = stream_ReadLine( p_demux->s ) ) )
     {
@@ -164,9 +180,8 @@ static int Demux( demux_t *p_demux )
             else
             {
                 /* handle multi-line descriptions */
-                buf = malloc( strlen( psz_description )
-                            + strlen( psz_attrvalue ) + 2 );
-                sprintf( buf, "%s\n%s", psz_description, psz_attrvalue );
+                if( asprintf( &buf, "%s\n%s", psz_description, psz_attrvalue ) == -1 )
+                    buf = NULL;
                 free( psz_description );
                 psz_description = buf;
             }
@@ -187,20 +202,17 @@ static int Demux( demux_t *p_demux )
     }
     else
     {
-        p_input = input_ItemNewExt( p_sys->p_playlist,
-                                    psz_url, psz_title, 0, NULL, -1 );
-#define SADD_INFO( type, field ) if( field ) { input_ItemAddInfo( \
-                    p_input, _("Google Video"), _(type), "%s", field ) ; }
+        p_input = input_item_New( p_demux, psz_url, psz_title );
+#define SADD_INFO( type, field ) if( field ) { input_item_AddInfo( \
+                    p_input, _("Google Video"), type, "%s", field ) ; }
         SADD_INFO( "gvp_version", psz_version );
         SADD_INFO( "docid", psz_docid );
         SADD_INFO( "description", psz_description );
-        playlist_AddWhereverNeeded( p_sys->p_playlist, p_input,
-                            p_sys->p_current, p_sys->p_item_in_category,
-                            (p_sys->i_parent_id > 0 ) ? VLC_TRUE: VLC_FALSE,
-                            PLAYLIST_APPEND );
+        input_item_AddSubItem( p_current_input, p_input );
+        vlc_gc_decref( p_input );
     }
 
-    HANDLE_PLAY_AND_RELEASE;
+    vlc_gc_decref(p_current_input);
 
     free( psz_version );
     free( psz_url );
@@ -208,12 +220,11 @@ static int Demux( demux_t *p_demux )
     free( psz_title );
     free( psz_description );
 
-    p_sys->p_playlist = NULL;
-
-    return VLC_SUCCESS;
+    return 0; /* Needed for correct operation of go back */
 }
 
 static int Control( demux_t *p_demux, int i_query, va_list args )
 {
+    VLC_UNUSED(p_demux); VLC_UNUSED(i_query); VLC_UNUSED(args);
     return VLC_EGENERIC;
 }