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

midi

开发平台:

Unix_Linux

  1. /*****************************************************************************
  2.  * audio_video.c: Audio/Video management : volume, snapshot, OSD
  3.  *****************************************************************************
  4.  * Copyright (C) 2005 the VideoLAN team
  5.  * $Id: cb28ccfacbe8fae680e1282d0cae041ce7e3b37b $
  6.  *
  7.  * Authors: Olivier Aubert <olivier.aubert@liris.univ-lyon1.fr>
  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. #ifdef HAVE_CONFIG_H
  24. # include "config.h"
  25. #endif
  26. #include "mediacontrol_internal.h"
  27. #include "libvlc_internal.h"
  28. #include "media_player_internal.h"
  29. #include <vlc/mediacontrol.h>
  30. #include <vlc/libvlc.h>
  31. #include <vlc_vout.h>
  32. #include <vlc_input.h>
  33. #include <vlc_osd.h>
  34. #include <vlc_block.h>
  35. #include <stdlib.h>                                      /* malloc(), free() */
  36. #include <string.h>
  37. #include <errno.h>                                                 /* ENOMEM */
  38. #include <stdio.h>
  39. #include <ctype.h>
  40. #ifdef HAVE_UNISTD_H
  41. #    include <unistd.h>
  42. #endif
  43. #ifdef HAVE_SYS_TIME_H
  44. #    include <sys/time.h>
  45. #endif
  46. #ifdef HAVE_SYS_TYPES_H
  47. #    include <sys/types.h>
  48. #endif
  49. mediacontrol_RGBPicture *
  50. mediacontrol_snapshot( mediacontrol_Instance *self,
  51.                        const mediacontrol_Position * a_position,
  52.                        mediacontrol_Exception *exception )
  53. {
  54.     (void)a_position;
  55.     vout_thread_t* p_vout;
  56.     input_thread_t *p_input;
  57.     mediacontrol_RGBPicture *p_pic;
  58.     libvlc_exception_t ex;
  59.     libvlc_exception_init( &ex );
  60.     mediacontrol_exception_init( exception );
  61.     p_input = libvlc_get_input_thread( self->p_media_player, &ex );
  62.     if( ! p_input )
  63.     {
  64.         RAISE_NULL( mediacontrol_InternalException, "No input" );
  65.     }
  66.     p_vout = input_GetVout( p_input );
  67.     vlc_object_release( p_input );
  68.     if( ! p_vout )
  69.     {
  70.         RAISE_NULL( mediacontrol_InternalException, "No video output" );
  71.     }
  72.     block_t *p_image;
  73.     video_format_t fmt;
  74.     if( vout_GetSnapshot( p_vout, &p_image, NULL, &fmt, "png", 500*1000 ) )
  75.     {
  76.         RAISE_NULL( mediacontrol_InternalException, "Snapshot exception" );
  77.         return NULL;
  78.     }
  79.     /* */
  80.     char *p_data = malloc( p_image->i_buffer );
  81.     if( p_data )
  82.     {
  83.         memcpy( p_data, p_image->p_buffer, p_image->i_buffer );
  84.         p_pic = private_mediacontrol_createRGBPicture( fmt.i_width,
  85.                                                        fmt.i_height,
  86.                                                        fmt.i_chroma,
  87.                                                        p_image->i_pts,
  88.                                                        p_data,
  89.                                                        p_image->i_buffer );
  90.     }
  91.     else
  92.     {
  93.         p_pic = NULL;
  94.     }
  95.     block_Release( p_image );
  96.     if( !p_pic )
  97.         RAISE_NULL( mediacontrol_InternalException, "Out of memory" );
  98.     return p_pic;
  99. }
  100. static
  101. int mediacontrol_showtext( vout_thread_t *p_vout, int i_channel,
  102.                            const char *psz_string, text_style_t *p_style,
  103.                            int i_flags, int i_hmargin, int i_vmargin,
  104.                            mtime_t i_start, mtime_t i_stop )
  105. {
  106.     return osd_ShowTextAbsolute( p_vout->p_spu, i_channel,
  107.                                  psz_string, p_style,
  108.                                  i_flags, i_hmargin, i_vmargin,
  109.                                  i_start, i_stop );
  110. }
  111. void
  112. mediacontrol_display_text( mediacontrol_Instance *self,
  113.                            const char * message,
  114.                            const mediacontrol_Position * begin,
  115.                            const mediacontrol_Position * end,
  116.                            mediacontrol_Exception *exception )
  117. {
  118.     vout_thread_t *p_vout = NULL;
  119.     input_thread_t *p_input;
  120.     libvlc_exception_t ex;
  121.     libvlc_exception_init( &ex );
  122.     mediacontrol_exception_init( exception );
  123.     if( !message )
  124.     {
  125.         RAISE_VOID( mediacontrol_InternalException, "Empty text" );
  126.     }
  127.     p_input = libvlc_get_input_thread( self->p_media_player, &ex );
  128.     if( ! p_input )
  129.     {
  130.         RAISE_VOID( mediacontrol_InternalException, "No input" );
  131.     }
  132.     p_vout = input_GetVout( p_input );
  133.     if( ! p_vout )
  134.     {
  135.         RAISE_VOID( mediacontrol_InternalException, "No video output" );
  136.     }
  137.     if( begin->origin == mediacontrol_RelativePosition &&
  138.         begin->value == 0 &&
  139.         end->origin == mediacontrol_RelativePosition )
  140.     {
  141.         mtime_t i_duration = 0;
  142.         mtime_t i_now = mdate();
  143.         i_duration = 1000 * private_mediacontrol_unit_convert(
  144.                                                               self->p_media_player,
  145.                                                               end->key,
  146.                                                               mediacontrol_MediaTime,
  147.                                                               end->value );
  148.         mediacontrol_showtext( p_vout, DEFAULT_CHAN, message, NULL,
  149.                                OSD_ALIGN_BOTTOM | OSD_ALIGN_LEFT, 0, 0,
  150.                                i_now, i_now + i_duration );
  151.     }
  152.     else
  153.     {
  154.         mtime_t i_debut, i_fin, i_now;
  155.         /* FIXME */
  156.         /* i_now = input_ClockGetTS( p_input, NULL, 0 ); */
  157.         i_now = mdate();
  158.         i_debut = private_mediacontrol_position2microsecond( self->p_media_player,
  159.                                             ( mediacontrol_Position* ) begin );
  160.         i_debut += i_now;
  161.         i_fin = private_mediacontrol_position2microsecond( self->p_media_player,
  162.                                           ( mediacontrol_Position * ) end );
  163.         i_fin += i_now;
  164.         vout_ShowTextAbsolute( p_vout, DEFAULT_CHAN, message, NULL,
  165.                                OSD_ALIGN_BOTTOM | OSD_ALIGN_LEFT, 0, 0,
  166.                                i_debut, i_fin );
  167.     }
  168.     vlc_object_release( p_vout );
  169. }
  170. unsigned short
  171. mediacontrol_sound_get_volume( mediacontrol_Instance *self,
  172.                                mediacontrol_Exception *exception )
  173. {
  174.     libvlc_exception_t ex;
  175.     int i_ret = 0;
  176.     mediacontrol_exception_init( exception );
  177.     libvlc_exception_init( &ex );
  178.     i_ret = libvlc_audio_get_volume( self->p_instance, &ex );
  179.     HANDLE_LIBVLC_EXCEPTION_ZERO( &ex );
  180.     /* FIXME: Normalize in [0..100] */
  181.     return (unsigned short)i_ret;
  182. }
  183. void
  184. mediacontrol_sound_set_volume( mediacontrol_Instance *self,
  185.                                const unsigned short volume,
  186.                                mediacontrol_Exception *exception )
  187. {
  188.     /* FIXME: Normalize in [0..100] */
  189.     libvlc_exception_t ex;
  190.     mediacontrol_exception_init( exception );
  191.     libvlc_exception_init( &ex );
  192.     libvlc_audio_set_volume( self->p_instance, volume, &ex );
  193.     HANDLE_LIBVLC_EXCEPTION_VOID( &ex );
  194. }
  195. int mediacontrol_set_visual( mediacontrol_Instance *self,
  196.                                     WINDOWHANDLE visual_id,
  197.                                     mediacontrol_Exception *exception )
  198. {
  199.     libvlc_exception_t ex;
  200.     mediacontrol_exception_init( exception );
  201.     libvlc_exception_init( &ex );
  202.     libvlc_media_player_set_drawable( self->p_media_player, (libvlc_drawable_t)visual_id, &ex );
  203.     HANDLE_LIBVLC_EXCEPTION_ZERO( &ex );
  204.     return true;
  205. }
  206. int
  207. mediacontrol_get_rate( mediacontrol_Instance *self,
  208.                mediacontrol_Exception *exception )
  209. {
  210.     libvlc_exception_t ex;
  211.     int i_ret;
  212.     mediacontrol_exception_init( exception );
  213.     libvlc_exception_init( &ex );
  214.     i_ret = libvlc_media_player_get_rate( self->p_media_player, &ex );
  215.     HANDLE_LIBVLC_EXCEPTION_ZERO( &ex );
  216.     return i_ret / 10;
  217. }
  218. void
  219. mediacontrol_set_rate( mediacontrol_Instance *self,
  220.                const int rate,
  221.                mediacontrol_Exception *exception )
  222. {
  223.     libvlc_exception_t ex;
  224.     mediacontrol_exception_init( exception );
  225.     libvlc_exception_init( &ex );
  226.     libvlc_media_player_set_rate( self->p_media_player, rate * 10, &ex );
  227.     HANDLE_LIBVLC_EXCEPTION_VOID( &ex );
  228. }
  229. int
  230. mediacontrol_get_fullscreen( mediacontrol_Instance *self,
  231.                  mediacontrol_Exception *exception )
  232. {
  233.     libvlc_exception_t ex;
  234.     int i_ret;
  235.     mediacontrol_exception_init( exception );
  236.     libvlc_exception_init( &ex );
  237.     i_ret = libvlc_get_fullscreen( self->p_media_player, &ex );
  238.     HANDLE_LIBVLC_EXCEPTION_ZERO( &ex );
  239.     return i_ret;
  240. }
  241. void
  242. mediacontrol_set_fullscreen( mediacontrol_Instance *self,
  243.                  const int b_fullscreen,
  244.                  mediacontrol_Exception *exception )
  245. {
  246.     libvlc_exception_t ex;
  247.     mediacontrol_exception_init( exception );
  248.     libvlc_exception_init( &ex );
  249.     libvlc_set_fullscreen( self->p_media_player, b_fullscreen, &ex );
  250.     HANDLE_LIBVLC_EXCEPTION_VOID( &ex );
  251. }