qtl.c
上传用户:kjfoods
上传日期:2020-07-06
资源大小:29949k
文件大小:12k
源码类别:

midi

开发平台:

Unix_Linux

  1. /*****************************************************************************
  2.  * qtl.c: QuickTime Media Link Importer
  3.  *****************************************************************************
  4.  * Copyright (C) 2006 the VideoLAN team
  5.  * $Id: b667b69704735341e1325560f6ec5cb772d5c4a0 $
  6.  *
  7.  * Authors: Antoine Cellerier <dionoea -@t- videolan -Dot- org>
  8.  *
  9.  * This program is free software; you can redistribute it and/or modify
  10.  * it under the terms of the GNU General Public License as published by
  11.  * the Free Software Foundation; either version 2 of the License, or
  12.  * (at your option) any later version.
  13.  *
  14.  * This program is distributed in the hope that it will be useful,
  15.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.  * GNU General Public License for more details.
  18.  *
  19.  * You should have received a copy of the GNU General Public License
  20.  * along with this program; if not, write to the Free Software
  21.  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  22.  *****************************************************************************/
  23. /*
  24. See
  25. http://developer.apple.com/documentation/QuickTime/QT6WhatsNew/Chap1/chapter_1_section_54.html
  26. and
  27. http://developer.apple.com/documentation/QuickTime/WhatsNewQT5/QT5NewChapt1/chapter_1_section_39.html
  28. autoplay - true/false
  29. controller - true/false
  30. fullscreen - normal/double/half/current/full
  31. href - url
  32. kioskmode - true/false
  33. loop - true/false/palindrome
  34. movieid - integer
  35. moviename - string
  36. playeveryframe - true/false
  37. qtnext - url
  38. quitwhendone - true/false
  39. src - url (required)
  40. type - mime type
  41. volume - 0 (mute) - 100 (max)
  42. */
  43. /*****************************************************************************
  44.  * Preamble
  45.  *****************************************************************************/
  46. #ifdef HAVE_CONFIG_H
  47. # include "config.h"
  48. #endif
  49. #include <vlc_common.h>
  50. #include <vlc_demux.h>
  51. #include "playlist.h"
  52. #include "vlc_xml.h"
  53. struct demux_sys_t
  54. {
  55.     input_item_t *p_current_input;
  56.     xml_t *p_xml;
  57.     xml_reader_t *p_xml_reader;
  58. };
  59. typedef enum { FULLSCREEN_NORMAL,
  60.                FULLSCREEN_DOUBLE,
  61.                FULLSCREEN_HALF,
  62.                FULLSCREEN_CURRENT,
  63.                FULLSCREEN_FULL } qtl_fullscreen_t;
  64. const char* ppsz_fullscreen[] = { "normal", "double", "half", "current", "full" };
  65. typedef enum { LOOP_TRUE,
  66.                LOOP_FALSE,
  67.                LOOP_PALINDROME } qtl_loop_t;
  68. const char* ppsz_loop[] = { "true", "false", "palindrome" };
  69. /*****************************************************************************
  70.  * Local prototypes
  71.  *****************************************************************************/
  72. static int Demux( demux_t *p_demux);
  73. static int Control( demux_t *p_demux, int i_query, va_list args );
  74. /*****************************************************************************
  75.  * Import_QTL: main import function
  76.  *****************************************************************************/
  77. int Import_QTL( vlc_object_t *p_this )
  78. {
  79.     DEMUX_BY_EXTENSION_MSG( ".qtl", "using QuickTime Media Link reader" );
  80.     p_demux->p_sys->p_xml = NULL;
  81.     p_demux->p_sys->p_xml_reader = NULL;
  82.     return VLC_SUCCESS;
  83. }
  84. /*****************************************************************************
  85.  * Deactivate: frees unused data
  86.  *****************************************************************************/
  87. void Close_QTL( vlc_object_t *p_this )
  88. {
  89.     demux_t *p_demux = (demux_t *)p_this;
  90.     demux_sys_t *p_sys = p_demux->p_sys;
  91.     if( p_sys->p_xml_reader )
  92.         xml_ReaderDelete( p_sys->p_xml, p_sys->p_xml_reader );
  93.     if( p_sys->p_xml )
  94.         xml_Delete( p_sys->p_xml );
  95.     free( p_sys );
  96. }
  97. static int Demux( demux_t *p_demux )
  98. {
  99.     demux_sys_t *p_sys = p_demux->p_sys;
  100.     xml_t *p_xml;
  101.     xml_reader_t *p_xml_reader;
  102.     char *psz_eltname = NULL;
  103.     input_item_t *p_input;
  104.     /* List of all possible attributes. The only required one is "src" */
  105.     bool b_autoplay = false;
  106.     bool b_controler = true;
  107.     qtl_fullscreen_t fullscreen = false;
  108.     char *psz_href = NULL;
  109.     bool b_kioskmode = false;
  110.     qtl_loop_t loop = LOOP_FALSE;
  111.     int i_movieid = -1;
  112.     char *psz_moviename = NULL;
  113.     bool b_playeveryframe = false;
  114.     char *psz_qtnext = NULL;
  115.     bool b_quitwhendone = false;
  116.     char *psz_src = NULL;
  117.     char *psz_mimetype = NULL;
  118.     int i_volume = 100;
  119.     INIT_PLAYLIST_STUFF;
  120.     p_sys->p_current_input = p_current_input;
  121.     p_xml = p_sys->p_xml = xml_Create( p_demux );
  122.     if( !p_xml ) return -1;
  123.     p_xml_reader = xml_ReaderCreate( p_xml, p_demux->s );
  124.     if( !p_xml_reader ) return -1;
  125.     p_sys->p_xml_reader = p_xml_reader;
  126.     /* check root node */
  127.     if( xml_ReaderRead( p_xml_reader ) != 1 )
  128.     {
  129.         msg_Err( p_demux, "invalid file (no root node)" );
  130.         return -1;
  131.     }
  132.     if( xml_ReaderNodeType( p_xml_reader ) != XML_READER_STARTELEM ||
  133.         ( psz_eltname = xml_ReaderName( p_xml_reader ) ) == NULL ||
  134.         strcmp( psz_eltname, "embed" ) )
  135.     {
  136.         msg_Err( p_demux, "invalid root node %i, %s",
  137.                  xml_ReaderNodeType( p_xml_reader ), psz_eltname );
  138.         free( psz_eltname );
  139.         /* second line has <?quicktime tag ... so we try to skip it */
  140.         msg_Dbg( p_demux, "trying to read one more node" );
  141.         xml_ReaderRead( p_xml_reader );
  142.         if( xml_ReaderNodeType( p_xml_reader ) != XML_READER_STARTELEM ||
  143.             ( psz_eltname = xml_ReaderName( p_xml_reader ) ) == NULL ||
  144.             strcmp( psz_eltname, "embed" ) )
  145.         {
  146.             msg_Err( p_demux, "invalid root node %i, %s",
  147.                      xml_ReaderNodeType( p_xml_reader ), psz_eltname );
  148.             free( psz_eltname );
  149.             return -1;
  150.         }
  151.     }
  152.     free( psz_eltname );
  153.     while( xml_ReaderNextAttr( p_sys->p_xml_reader ) == VLC_SUCCESS )
  154.     {
  155.         char *psz_attrname = xml_ReaderName( p_sys->p_xml_reader );
  156.         char *psz_attrvalue = xml_ReaderValue( p_sys->p_xml_reader );
  157.         if( !psz_attrname || !psz_attrvalue )
  158.         {
  159.             free( psz_attrname );
  160.             free( psz_attrvalue );
  161.             return -1;
  162.         }
  163.         if( !strcmp( psz_attrname, "autoplay" ) )
  164.         {
  165.             if( !strcmp( psz_attrvalue, "true" ) )
  166.             {
  167.                 b_autoplay = true;
  168.             }
  169.             else
  170.             {
  171.                 b_autoplay = false;
  172.             }
  173.         }
  174.         else if( !strcmp( psz_attrname, "controler" ) )
  175.         {
  176.             if( !strcmp( psz_attrvalue, "false" ) )
  177.             {
  178.                 b_controler = false;
  179.             }
  180.             else
  181.             {
  182.                 b_controler = true;
  183.             }
  184.         }
  185.         else if( !strcmp( psz_attrname, "fullscreen" ) )
  186.         {
  187.             if( !strcmp( psz_attrvalue, "double" ) )
  188.             {
  189.                 fullscreen = FULLSCREEN_DOUBLE;
  190.             }
  191.             else if( !strcmp( psz_attrvalue, "half" ) )
  192.             {
  193.                 fullscreen = FULLSCREEN_HALF;
  194.             }
  195.             else if( !strcmp( psz_attrvalue, "current" ) )
  196.             {
  197.                 fullscreen = FULLSCREEN_CURRENT;
  198.             }
  199.             else if( !strcmp( psz_attrvalue, "full" ) )
  200.             {
  201.                 fullscreen = FULLSCREEN_FULL;
  202.             }
  203.             else
  204.             {
  205.                 fullscreen = FULLSCREEN_NORMAL;
  206.             }
  207.         }
  208.         else if( !strcmp( psz_attrname, "href" ) )
  209.         {
  210.             psz_href = psz_attrvalue;
  211.             psz_attrvalue = NULL;
  212.         }
  213.         else if( !strcmp( psz_attrname, "kioskmode" ) )
  214.         {
  215.             if( !strcmp( psz_attrvalue, "true" ) )
  216.             {
  217.                 b_kioskmode = true;
  218.             }
  219.             else
  220.             {
  221.                 b_kioskmode = false;
  222.             }
  223.         }
  224.         else if( !strcmp( psz_attrname, "loop" ) )
  225.         {
  226.             if( !strcmp( psz_attrvalue, "true" ) )
  227.             {
  228.                 loop = LOOP_TRUE;
  229.             }
  230.             else if( !strcmp( psz_attrvalue, "palindrome" ) )
  231.             {
  232.                 loop = LOOP_PALINDROME;
  233.             }
  234.             else
  235.             {
  236.                 loop = LOOP_FALSE;
  237.             }
  238.         }
  239.         else if( !strcmp( psz_attrname, "movieid" ) )
  240.         {
  241.             i_movieid = atoi( psz_attrvalue );
  242.         }
  243.         else if( !strcmp( psz_attrname, "moviename" ) )
  244.         {
  245.             psz_moviename = psz_attrvalue;
  246.             psz_attrvalue = NULL;
  247.         }
  248.         else if( !strcmp( psz_attrname, "playeveryframe" ) )
  249.         {
  250.             if( !strcmp( psz_attrvalue, "true" ) )
  251.             {
  252.                 b_playeveryframe = true;
  253.             }
  254.             else
  255.             {
  256.                 b_playeveryframe = false;
  257.             }
  258.         }
  259.         else if( !strcmp( psz_attrname, "qtnext" ) )
  260.         {
  261.             psz_qtnext = psz_attrvalue;
  262.             psz_attrvalue = NULL;
  263.         }
  264.         else if( !strcmp( psz_attrname, "quitwhendone" ) )
  265.         {
  266.             if( !strcmp( psz_attrvalue, "true" ) )
  267.             {
  268.                 b_quitwhendone = true;
  269.             }
  270.             else
  271.             {
  272.                 b_quitwhendone = false;
  273.             }
  274.         }
  275.         else if( !strcmp( psz_attrname, "src" ) )
  276.         {
  277.             psz_src = psz_attrvalue;
  278.             psz_attrvalue = NULL;
  279.         }
  280.         else if( !strcmp( psz_attrname, "mimetype" ) )
  281.         {
  282.             psz_mimetype = psz_attrvalue;
  283.             psz_attrvalue = NULL;
  284.         }
  285.         else if( !strcmp( psz_attrname, "volume" ) )
  286.         {
  287.             i_volume = atoi( psz_attrvalue );
  288.         }
  289.         else
  290.         {
  291.             msg_Dbg( p_demux, "Attribute %s with value %s isn't valid",
  292.                      psz_attrname, psz_attrvalue );
  293.         }
  294.         free( psz_attrname );
  295.         free( psz_attrvalue );
  296.     }
  297.     msg_Dbg( p_demux, "autoplay: %s (unused by VLC)",
  298.              b_autoplay==true ? "true": "false" );
  299.     msg_Dbg( p_demux, "controler: %s (unused by VLC)",
  300.              b_controler==true?"true": "false" );
  301.     msg_Dbg( p_demux, "fullscreen: %s (unused by VLC)",
  302.              ppsz_fullscreen[fullscreen] );
  303.     msg_Dbg( p_demux, "href: %s", psz_href );
  304.     msg_Dbg( p_demux, "kioskmode: %s (unused by VLC)",
  305.              b_kioskmode==true?"true":"false" );
  306.     msg_Dbg( p_demux, "loop: %s (unused by VLC)", ppsz_loop[loop] );
  307.     msg_Dbg( p_demux, "movieid: %d (unused by VLC)", i_movieid );
  308.     msg_Dbg( p_demux, "moviename: %s", psz_moviename );
  309.     msg_Dbg( p_demux, "playeverframe: %s (unused by VLC)",
  310.              b_playeveryframe==true?"true":"false" );
  311.     msg_Dbg( p_demux, "qtnext: %s", psz_qtnext );
  312.     msg_Dbg( p_demux, "quitwhendone: %s (unused by VLC)",
  313.              b_quitwhendone==true?"true":"false" );
  314.     msg_Dbg( p_demux, "src: %s", psz_src );
  315.     msg_Dbg( p_demux, "mimetype: %s", psz_mimetype );
  316.     msg_Dbg( p_demux, "volume: %d (unused by VLC)", i_volume );
  317.     if( !psz_src )
  318.     {
  319.         msg_Err( p_demux, "Mandatory attribute 'src' not found" );
  320.     }
  321.     else
  322.     {
  323.         p_input = input_item_New( p_demux, psz_src, psz_moviename );
  324. #define SADD_INFO( type, field ) if( field ) { input_item_AddInfo( 
  325.                     p_input, "QuickTime Media Link", type, "%s", field ) ; }
  326.         SADD_INFO( "href", psz_href );
  327.         SADD_INFO( _("Mime"), psz_mimetype );
  328.         input_item_AddSubItem( p_current_input, p_input );
  329.         vlc_gc_decref( p_input );
  330.         if( psz_qtnext )
  331.         {
  332.             p_input = input_item_New( p_demux, psz_qtnext, NULL );
  333.             input_item_AddSubItem( p_current_input, p_input );
  334.             vlc_gc_decref( p_input );
  335.         }
  336.     }
  337.     HANDLE_PLAY_AND_RELEASE;
  338.     free( psz_href );
  339.     free( psz_moviename );
  340.     free( psz_qtnext );
  341.     free( psz_src );
  342.     free( psz_mimetype );
  343.     return 0; /* Needed for correct operation of go back */
  344. }
  345. static int Control( demux_t *p_demux, int i_query, va_list args )
  346. {
  347.     VLC_UNUSED(p_demux); VLC_UNUSED(i_query); VLC_UNUSED(args);
  348.     return VLC_EGENERIC;
  349. }