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

midi

开发平台:

Unix_Linux

  1. /*****************************************************************************
  2.  * swscale_maemo.c: scaling and chroma conversion using libswscale_nokia770
  3.  *****************************************************************************
  4.  * Copyright (C) 1999-2008 the VideoLAN team
  5.  * $Id: 6afd21000c4d61aeab287062885c6ca3525f70f4 $
  6.  *
  7.  * Authors: Antoine Lejeune <phytos@videolan.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.  * Preamble
  25.  *****************************************************************************/
  26. #ifdef HAVE_CONFIG_H
  27. # include "config.h"
  28. #endif
  29. #include <vlc_common.h>
  30. #include <vlc_plugin.h>
  31. #include <vlc_vout.h>
  32. #include <vlc_filter.h>
  33. #include "libswscale_nokia770/arm_jit_swscale.h"
  34. #include "libswscale_nokia770/arm_colorconv.h"
  35. /****************************************************************************
  36.  * Local prototypes
  37.  ****************************************************************************/
  38. static int  OpenScaler( vlc_object_t * );
  39. static void CloseScaler( vlc_object_t * );
  40. static picture_t *Filter( filter_t *, picture_t * );
  41. static int Init( filter_t * );
  42. /*****************************************************************************
  43.  * Module descriptor
  44.  *****************************************************************************/
  45. vlc_module_begin();
  46.     set_description( N_("Video scaling filter") );
  47.     set_capability( "video filter2", 1000 );
  48.     set_category( CAT_VIDEO );
  49.     set_subcategory( SUBCAT_VIDEO_VFILTER );
  50.     set_callbacks( OpenScaler, CloseScaler );
  51. vlc_module_end();
  52. /*****************************************************************************
  53.  * filter_sys_t : filter descriptor
  54.  *****************************************************************************/
  55. struct filter_sys_t
  56. {
  57.     struct SwsContextArmJit *ctx;
  58.     es_format_t fmt_in;
  59.     es_format_t fmt_out;
  60. };
  61. /*****************************************************************************
  62.  * OpenScaler: probe the filter and return score
  63.  *****************************************************************************/
  64. static int OpenScaler( vlc_object_t *p_this )
  65. {
  66.     filter_t *p_filter = (filter_t*)p_this;
  67.     filter_sys_t *p_sys;
  68.     /* Allocate the memory needed to store the decoder's structure */
  69.     if( ( p_filter->p_sys = p_sys =
  70.           (filter_sys_t *)malloc(sizeof(filter_sys_t)) ) == NULL )
  71.     {
  72.         return VLC_ENOMEM;
  73.     }
  74.     /* Misc init */
  75.     p_sys->ctx = NULL;
  76.     p_filter->pf_video_filter = Filter;
  77.     es_format_Init( &p_sys->fmt_in, 0, 0 );
  78.     es_format_Init( &p_sys->fmt_out, 0, 0 );
  79.     if( Init( p_filter ) )
  80.     {
  81.         free( p_sys );
  82.         return VLC_EGENERIC;
  83.     }
  84.     msg_Dbg( p_filter, "%ix%i chroma: %4.4s -> %ix%i chroma: %4.4s",
  85.              p_filter->fmt_in.video.i_width, p_filter->fmt_in.video.i_height,
  86.              (char *)&p_filter->fmt_in.video.i_chroma,
  87.              p_filter->fmt_out.video.i_width, p_filter->fmt_out.video.i_height,
  88.              (char *)&p_filter->fmt_out.video.i_chroma );
  89.     return VLC_SUCCESS;
  90. }
  91. /*****************************************************************************
  92.  * CloseFilter: clean up the filter
  93.  *****************************************************************************/
  94. static void CloseScaler( vlc_object_t *p_this )
  95. {
  96.     filter_t *p_filter = (filter_t*)p_this;
  97.     filter_sys_t *p_sys = p_filter->p_sys;
  98.     if( p_sys->ctx )
  99.         sws_arm_jit_free( p_sys->ctx );
  100.     free( p_sys );
  101. }
  102. /*****************************************************************************
  103.  * Helpers
  104.  *****************************************************************************/
  105. static bool IsFmtSimilar( const video_format_t *p_fmt1, const video_format_t *p_fmt2 )
  106. {
  107.     return p_fmt1->i_chroma == p_fmt2->i_chroma &&
  108.            p_fmt1->i_width  == p_fmt2->i_width &&
  109.            p_fmt1->i_height == p_fmt2->i_height;
  110. }
  111. static int Init( filter_t *p_filter )
  112. {
  113.     filter_sys_t *p_sys = p_filter->p_sys;
  114.     if( IsFmtSimilar( &p_filter->fmt_in.video, &p_sys->fmt_in ) &&
  115.         IsFmtSimilar( &p_filter->fmt_out.video, &p_sys->fmt_out ) &&
  116.         p_sys->ctx )
  117.     {
  118.         return VLC_SUCCESS;
  119.     }
  120.     if( ( p_filter->fmt_in.video.i_chroma != VLC_FOURCC('I','4','2','0') &&
  121.           p_filter->fmt_in.video.i_chroma != VLC_FOURCC('I','Y','U','V') &&
  122.           p_filter->fmt_in.video.i_chroma != VLC_FOURCC('Y','V','1','2') ) ||
  123.           p_filter->fmt_out.video.i_chroma != VLC_FOURCC('Y','4','2','0') )
  124.     {
  125.         msg_Err( p_filter, "format not supported" );
  126.         return VLC_EGENERIC;
  127.     }
  128.     if( p_sys->ctx )
  129.         sws_arm_jit_free( p_sys->ctx );
  130.     p_sys->ctx =
  131.         sws_arm_jit_create_omapfb_yuv420_scaler_armv6(
  132.             p_filter->fmt_in.video.i_width,
  133.             p_filter->fmt_in.video.i_height,
  134.             p_filter->fmt_out.video.i_width,
  135.             p_filter->fmt_out.video.i_height, 2 );
  136.     if( !p_sys->ctx )
  137.     {
  138.         msg_Err( p_filter, "could not init SwScaler" );
  139.         return VLC_EGENERIC;
  140.     }
  141.     p_sys->fmt_in = p_filter->fmt_in;
  142.     p_sys->fmt_out = p_filter->fmt_out;
  143.     return VLC_SUCCESS;
  144. }
  145. /****************************************************************************
  146.  * Filter: the whole thing
  147.  ****************************************************************************
  148.  * This function is called just after the thread is launched.
  149.  ****************************************************************************/
  150. static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
  151. {
  152.     filter_sys_t *p_sys = p_filter->p_sys;
  153.     uint8_t *src[3]; int src_stride[3];
  154.     uint8_t *dst[3]; int dst_stride[3];
  155.     picture_t *p_pic_dst;
  156.     int i_plane;
  157.     int i_nb_planes = p_pic->i_planes;
  158.     /* Check if format properties changed */
  159.     if( Init( p_filter ) != VLC_SUCCESS )
  160.         return NULL;
  161.     /* Request output picture */
  162.     p_pic_dst = p_filter->pf_vout_buffer_new( p_filter );
  163.     if( !p_pic_dst )
  164.     {
  165.         msg_Warn( p_filter, "can't get output picture" );
  166.         return NULL;
  167.     }
  168.     for( i_plane = 0; i_plane < __MIN(3, p_pic->i_planes); i_plane++ )
  169.     {
  170.         src[i_plane] = p_pic->p[i_plane].p_pixels;
  171.         src_stride[i_plane] = p_pic->p[i_plane].i_pitch;
  172.     }
  173.     for( i_plane = 0; i_plane < __MIN(3, i_nb_planes); i_plane++ )
  174.     {
  175.         dst[i_plane] = p_pic_dst->p[i_plane].p_pixels;
  176.         dst_stride[i_plane] = p_pic_dst->p[i_plane].i_pitch;
  177.     }
  178.     sws_arm_jit_scale( p_sys->ctx, src, src_stride, 0,
  179.                        p_filter->fmt_in.video.i_height, dst, dst_stride);
  180.     picture_CopyProperties( p_pic_dst, p_pic );
  181.     picture_Release( p_pic );
  182.     return p_pic_dst;
  183. }