[vlc-devel] [PATCH 4/4] Add support to play multiple video instances in Android.

Paulo Vitor Magacho da Silva pvmagacho at gmail.com
Thu Jan 15 19:35:53 CET 2015


Hi,
I will probably have to update these patches. Could you tell me if they
could get applied?
Thank you,
Paulo

2014-12-17 21:03 GMT-02:00 Paulo Vitor Magacho da Silva <pvmagacho at gmail.com
>:

> Hi,
> I wonder if this will be applied ?
> Thanks,
> Paulo
>
> 2014-12-11 1:16 GMT-02:00 Paulo Vitor Magacho da Silva <
> pvmagacho at gmail.com>:
>
>> ---
>>  modules/codec/omxil/android_mediacodec.c      | 30 +++++++++-----
>>  modules/codec/omxil/omxil.c                   | 27 +++++++++----
>>  modules/codec/omxil/omxil.h                   |  3 ++
>>  modules/video_output/android/android_window.c | 58
>> ++++++++++++++++-----------
>>  modules/video_output/android/nativewindow.c   | 14 +++----
>>  modules/video_output/android/surface.c        | 47 ++++++++++++++--------
>>  modules/video_output/android/utils.h          |  3 ++
>>  7 files changed, 119 insertions(+), 63 deletions(-)
>>
>> diff --git a/modules/codec/omxil/android_mediacodec.c
>> b/modules/codec/omxil/android_mediacodec.c
>> index 2d0d346..015a27c 100644
>> --- a/modules/codec/omxil/android_mediacodec.c
>> +++ b/modules/codec/omxil/android_mediacodec.c
>> @@ -50,13 +50,15 @@
>>
>>  #define THREAD_NAME "android_mediacodec"
>>
>> +typedef struct android_surf_value_t android_surf_value_t;
>> +
>>  extern int jni_attach_thread(JNIEnv **env, const char *thread_name);
>>  extern void jni_detach_thread();
>>  /* JNI functions to get/set an Android Surface object. */
>> -extern jobject jni_LockAndGetAndroidJavaSurface();
>> -extern void jni_UnlockAndroidSurface();
>> -extern void jni_EventHardwareAccelerationError();
>> -extern bool jni_IsVideoPlayerActivityCreated();
>> +extern jobject jni_LockAndGetAndroidJavaSurface(android_surf_value_t
>> *object);
>> +extern void jni_UnlockAndroidSurface(android_surf_value_t *object);
>> +extern void jni_EventHardwareAccelerationError(android_surf_value_t
>> *android_surface);
>> +extern bool jni_IsVideoPlayerActivityCreated(android_surf_value_t
>> *android_surface);
>>
>>  /* Implementation of a circular buffer of timestamps with overwriting
>>   * of older values. MediaCodec has only one type of timestamp, if a
>> @@ -172,6 +174,8 @@ struct decoder_sys_t
>>      picture_t** inflight_picture; /**< stores the inflight picture for
>> each output buffer or NULL */
>>
>>      timestamp_fifo_t *timestamp_fifo;
>> +
>> +    android_surf_value_t *object;
>>  };
>>
>>  enum Types
>> @@ -325,6 +329,12 @@ static int OpenDecoder(vlc_object_t *p_this)
>>      if ((p_dec->p_sys = p_sys = calloc(1, sizeof(*p_sys))) == NULL)
>>          return VLC_ENOMEM;
>>
>> +    p_sys->object = var_CreateGetAddress (p_dec,
>> "drawable-androidobject");
>> +    if (!p_sys->object) {
>> +        msg_Warn(p_dec, "No android_surf_value_t set.");
>> +        return VLC_EGENERIC;
>> +    }
>> +
>>      p_dec->pf_decode_video = DecodeVideo;
>>
>>      p_dec->fmt_out.i_cat = p_dec->fmt_in.i_cat;
>> @@ -504,7 +514,7 @@ static int OpenDecoder(vlc_object_t *p_this)
>>      /* If the VideoPlayerActivity is not started, MediaCodec opaque
>>         direct rendering should be disabled since no surface will be
>>         attached to the JNI. */
>> -    p_sys->direct_rendering = jni_IsVideoPlayerActivityCreated() &&
>> var_InheritBool(p_dec, CFG_PREFIX "dr");
>> +    p_sys->direct_rendering =
>> jni_IsVideoPlayerActivityCreated(p_sys->object) && var_InheritBool(p_dec,
>> CFG_PREFIX "dr");
>>      if (p_sys->direct_rendering) {
>>          if (p_dec->fmt_in.video.orientation != ORIENT_NORMAL) {
>>              int i_angle;
>> @@ -527,14 +537,14 @@ static int OpenDecoder(vlc_object_t *p_this)
>>                                     i_angle);
>>          }
>>
>> -        jobject surf = jni_LockAndGetAndroidJavaSurface();
>> +        jobject surf = jni_LockAndGetAndroidJavaSurface(p_sys->object);
>>          if (surf) {
>>              // Configure MediaCodec with the Android surface.
>>              (*env)->CallVoidMethod(env, p_sys->codec, p_sys->configure,
>> format, surf, NULL, 0);
>>              if ((*env)->ExceptionOccurred(env)) {
>>                  msg_Warn(p_dec, "Exception occurred in
>> MediaCodec.configure with an output surface.");
>>                  (*env)->ExceptionClear(env);
>> -                jni_UnlockAndroidSurface();
>> +                jni_UnlockAndroidSurface(p_sys->object);
>>                  goto error;
>>              }
>>              p_dec->fmt_out.i_codec = VLC_CODEC_ANDROID_OPAQUE;
>> @@ -542,7 +552,7 @@ static int OpenDecoder(vlc_object_t *p_this)
>>              msg_Warn(p_dec, "Failed to get the Android Surface,
>> disabling direct rendering.");
>>              p_sys->direct_rendering = false;
>>          }
>> -        jni_UnlockAndroidSurface();
>> +        jni_UnlockAndroidSurface(p_sys->object);
>>      }
>>      if (!p_sys->direct_rendering) {
>>          (*env)->CallVoidMethod(env, p_sys->codec, p_sys->configure,
>> format, NULL, NULL, 0);
>> @@ -597,6 +607,8 @@ static void CloseDecoder(vlc_object_t *p_this)
>>      if (!p_sys)
>>          return;
>>
>> +    var_Destroy (p_dec, "drawable-androidobject");
>> +
>>      /* Invalidate all pictures that are currently in flight in order
>>       * to prevent the vout from using destroyed output buffers. */
>>      if (p_sys->direct_rendering)
>> @@ -906,7 +918,7 @@ static picture_t *DecodeVideo(decoder_t *p_dec,
>> block_t **pp_block)
>>          block_Release(p_block);
>>          if (!p_sys->error_event_sent) {
>>              /* Signal the error to the Java. */
>> -            jni_EventHardwareAccelerationError();
>> +            jni_EventHardwareAccelerationError(p_sys->object);
>>              p_sys->error_event_sent = true;
>>          }
>>          return NULL;
>> diff --git a/modules/codec/omxil/omxil.c b/modules/codec/omxil/omxil.c
>> index 03814d0..5c58f07 100644
>> --- a/modules/codec/omxil/omxil.c
>> +++ b/modules/codec/omxil/omxil.c
>> @@ -70,9 +70,9 @@
>>  #define THREAD_NAME "omxil"
>>  extern int jni_attach_thread(JNIEnv **env, const char *thread_name);
>>  extern void jni_detach_thread();
>> -extern jobject jni_LockAndGetAndroidJavaSurface();
>> -extern void jni_UnlockAndroidSurface();
>> -extern bool jni_IsVideoPlayerActivityCreated();
>> +extern jobject jni_LockAndGetAndroidJavaSurface(android_surf_value_t
>> *object);
>> +extern void jni_UnlockAndroidSurface(android_surf_value_t *object);
>> +extern bool jni_IsVideoPlayerActivityCreated(android_surf_value_t
>> *android_surface);
>>  #endif
>>
>>
>>  /*****************************************************************************
>> @@ -489,7 +489,7 @@ static OMX_ERRORTYPE AllocateBuffers(decoder_t
>> *p_dec, OmxPort *p_port)
>>                                      p_port->i_port_index, 0,
>>                                      p_port->definition.nBufferSize);
>>              OMX_DBG( "OMX_AllocateBuffer(%d) %p, %p", def->eDir,
>> -                     p_port->pp_buffers[i], p_port->pp_buffers[i] ?
>> +                     p_port->pp_buffers[i], p_port->pp_buffers[i] ?
>>                       p_port->pp_buffers[i]->pBuffer : NULL );
>>          }
>>
>> @@ -1056,6 +1056,15 @@ static int OpenGeneric( vlc_object_t *p_this, bool
>> b_encode )
>>          return VLC_ENOMEM;
>>      }
>>
>> +#if defined(USE_IOMX)
>> +    p_sys->object = var_CreateGetAddress (p_dec,
>> "drawable-androidobject");
>> +    if (!p_sys->object) {
>> +        msg_Warn(p_dec, "No android_surf_value_t set.");
>> +        DeinitOmxCore();
>> +        return VLC_EGENERIC;
>> +    }
>> +#endif
>> +
>>      /* Initialise the thread properties */
>>      if(!b_encode)
>>      {
>> @@ -1078,7 +1087,7 @@ static int OpenGeneric( vlc_object_t *p_this, bool
>> b_encode )
>>      p_sys->in.p_fmt = &p_dec->fmt_in;
>>      OMX_FIFO_INIT (&p_sys->out.fifo, pInputPortPrivate );
>>  #if defined(USE_IOMX)
>> -    p_sys->out.b_direct = jni_IsVideoPlayerActivityCreated() &&
>> var_InheritBool(p_dec, CFG_PREFIX "dr");
>> +    p_sys->out.b_direct =
>> jni_IsVideoPlayerActivityCreated(p_sys->object) && var_InheritBool(p_dec,
>> CFG_PREFIX "dr");
>>  #else
>>      p_sys->out.b_direct = false;
>>  #endif
>> @@ -1913,6 +1922,8 @@ static void CloseGeneric( vlc_object_t *p_this )
>>      OMX_FIFO_DESTROY( &p_sys->in.fifo );
>>      OMX_FIFO_DESTROY( &p_sys->out.fifo );
>>
>> +    var_Destroy (p_dec, "drawable-androidobject");
>> +
>>      free( p_sys );
>>  }
>>
>> @@ -2089,9 +2100,9 @@ static void HwBuffer_Init( decoder_t *p_dec,
>> OmxPort *p_port )
>>          goto error;
>>      }
>>
>> -    surf = jni_LockAndGetAndroidJavaSurface();
>> +    surf = jni_LockAndGetAndroidJavaSurface(p_dec->p_sys->object);
>>      if( !surf ) {
>> -        jni_UnlockAndroidSurface();
>> +        jni_UnlockAndroidSurface(p_dec->p_sys->object);
>>          msg_Warn( p_dec, "jni_LockAndGetAndroidJavaSurface failed" );
>>          goto error;
>>      }
>> @@ -2100,7 +2111,7 @@ static void HwBuffer_Init( decoder_t *p_dec,
>> OmxPort *p_port )
>>      p_port->p_hwbuf->window =
>> p_port->p_hwbuf->native_window.winFromSurface( p_env, surf );
>>      jni_detach_thread();
>>
>> -    jni_UnlockAndroidSurface();
>> +    jni_UnlockAndroidSurface(p_dec->p_sys->object);
>>      if( !p_port->p_hwbuf->window ) {
>>          msg_Warn( p_dec, "winFromSurface failed" );
>>          goto error;
>> diff --git a/modules/codec/omxil/omxil.h b/modules/codec/omxil/omxil.h
>> index 911f5f6..02279a3 100644
>> --- a/modules/codec/omxil/omxil.h
>> +++ b/modules/codec/omxil/omxil.h
>> @@ -138,4 +138,7 @@ struct decoder_sys_t
>>      size_t i_nal_size_length; /* Length of the NAL size field for H264 */
>>      int b_use_pts;
>>
>> +#if defined(USE_IOMX)
>> +    android_surf_value_t *object;
>> +#endif
>>  };
>> diff --git a/modules/video_output/android/android_window.c
>> b/modules/video_output/android/android_window.c
>> index 5c50975..eee7719 100644
>> --- a/modules/video_output/android/android_window.c
>> +++ b/modules/video_output/android/android_window.c
>> @@ -70,14 +70,15 @@ vlc_module_end()
>>  extern int jni_attach_thread(JNIEnv **env, const char *thread_name);
>>  extern void jni_detach_thread();
>>
>> -extern jobject jni_LockAndGetAndroidJavaSurface();
>> -extern jobject jni_LockAndGetSubtitlesSurface();
>> -extern void  jni_UnlockAndroidSurface();
>> -extern bool  jni_LockAndGetIsSurfaceAttached();
>> +extern jobject jni_LockAndGetAndroidJavaSurface(android_surf_value_t
>> *object);
>> +extern jobject jni_LockAndGetSubtitlesSurface(android_surf_value_t
>> *object);
>>
>> -extern void  jni_SetSurfaceLayout(int width, int height, int
>> visible_width, int visible_height, int sar_num, int sar_den);
>> -extern int jni_ConfigureSurface(jobject jsurf, int width, int height,
>> int hal, bool *configured);
>> -extern int jni_GetWindowSize(int *width, int *height);
>> +extern void  jni_UnlockAndroidSurface(android_surf_value_t *object);
>> +extern bool  jni_LockAndGetIsSurfaceAttached(android_surf_value_t
>> *object);
>> +
>> +extern void  jni_SetSurfaceLayout(android_surf_value_t *object, int
>> width, int height, int visible_width, int visible_height, int sar_num, int
>> sar_den);
>> +extern int jni_ConfigureSurface(android_surf_value_t *object, int width,
>> int height, int hal, bool *configured);
>> +extern int jni_GetWindowSize(android_surf_value_t *object, int *width,
>> int *height);
>>
>>  static const vlc_fourcc_t subpicture_chromas[] =
>>  {
>> @@ -137,9 +138,11 @@ struct vout_display_sys_t
>>      bool b_has_subpictures;
>>
>>      uint8_t hash[16];
>> +
>> +    android_surf_value_t *object;
>>  };
>>
>> -static int UpdateWindowSize(video_format_t *p_fmt, bool b_cropped)
>> +static int UpdateWindowSize(vout_display_sys_t *sys, video_format_t
>> *p_fmt, bool b_cropped)
>>  {
>>      unsigned int i_width, i_height;
>>      unsigned int i_sar_num = 1, i_sar_den = 1;
>> @@ -159,7 +162,8 @@ static int UpdateWindowSize(video_format_t *p_fmt,
>> bool b_cropped)
>>          i_height = rot_fmt.i_height;
>>      }
>>
>> -    jni_SetSurfaceLayout(i_width, i_height,
>> +    jni_SetSurfaceLayout(sys->object,
>> +                         i_width, i_height,
>>                           rot_fmt.i_visible_width,
>>                           rot_fmt.i_visible_height,
>>                           i_sar_num,
>> @@ -437,7 +441,7 @@ static int
>> AndroidWindow_ConfigureSurface(vout_display_sys_t *sys,
>>       * if jni_ConfigureSurface succeed, you need to get a new surface
>> handle.
>>       * That's why AndroidWindow_SetSurface is called again here.
>>       */
>> -    err = jni_ConfigureSurface(p_window->jsurf,
>> +    err = jni_ConfigureSurface(sys->object,
>>                                 p_window->fmt.i_width,
>>                                 p_window->fmt.i_height,
>>                                 p_window->i_android_hal,
>> @@ -562,9 +566,9 @@ static int
>> AndroidWindow_LockPicture(vout_display_sys_t *sys,
>>  static int SetupWindowSurface(vout_display_sys_t *sys, unsigned
>> i_pic_count)
>>  {
>>      int err;
>> -    jobject jsurf = jni_LockAndGetAndroidJavaSurface();
>> +    jobject jsurf = jni_LockAndGetAndroidJavaSurface(sys->object);
>>      err = AndroidWindow_SetSurface(sys, sys->p_window, jsurf);
>> -    jni_UnlockAndroidSurface();
>> +    jni_UnlockAndroidSurface(sys->object);
>>      err = err == 0 ? AndroidWindow_Setup(sys, sys->p_window,
>> i_pic_count) : err;
>>      return err;
>>  }
>> @@ -572,9 +576,9 @@ static int SetupWindowSurface(vout_display_sys_t
>> *sys, unsigned i_pic_count)
>>  static int SetupWindowSubtitleSurface(vout_display_sys_t *sys)
>>  {
>>      int err;
>> -    jobject jsurf = jni_LockAndGetSubtitlesSurface();
>> +    jobject jsurf = jni_LockAndGetSubtitlesSurface(sys->object);
>>      err = AndroidWindow_SetSurface(sys, sys->p_sub_window, jsurf);
>> -    jni_UnlockAndroidSurface();
>> +    jni_UnlockAndroidSurface(sys->object);
>>      err = err == 0 ? AndroidWindow_Setup(sys, sys->p_sub_window, 1) :
>> err;
>>      return err;
>>  }
>> @@ -602,7 +606,7 @@ static void SendEventDisplaySize(vout_display_t *vd)
>>      vout_display_sys_t *sys = vd->sys;
>>      int i_display_width, i_display_height;
>>
>> -    if (jni_GetWindowSize(&i_display_width, &i_display_height) == 0
>> +    if (jni_GetWindowSize(sys->object, &i_display_width,
>> &i_display_height) == 0
>>          && i_display_width != 0 && i_display_height != 0
>>          && (i_display_width != sys->i_display_width
>>           || i_display_height != sys->i_display_height))
>> @@ -624,6 +628,12 @@ static int Open(vlc_object_t *p_this)
>>      if (!sys)
>>          return VLC_ENOMEM;
>>
>> +    sys->object = var_CreateGetAddress (vd, "drawable-androidobject");
>> +    if (!sys->object) {
>> +        msg_Err(vd, "No android_surf_value_t set.");
>> +        goto error;
>> +    }
>> +
>>      sys->p_library = LoadNativeWindowAPI(&sys->anw);
>>      if (!sys->p_library) {
>>          msg_Err(vd, "Could not initialize NativeWindow API.");
>> @@ -716,6 +726,8 @@ static void Close(vlc_object_t *p_this)
>>      vout_display_t *vd = (vout_display_t *)p_this;
>>      vout_display_sys_t *sys = vd->sys;
>>
>> +    var_Destroy (vd, "drawable-androidobject");
>> +
>>      if (!sys)
>>          return;
>>
>> @@ -792,7 +804,7 @@ static picture_pool_t *PoolAlloc(vout_display_t *vd,
>> unsigned requested_count)
>>      requested_count = sys->p_window->i_pic_count;
>>      msg_Dbg(vd, "PoolAlloc: got %d frames", requested_count);
>>
>> -    UpdateWindowSize(&sys->p_window->fmt, sys->p_window->b_use_priv);
>> +    UpdateWindowSize(sys, &sys->p_window->fmt,
>> sys->p_window->b_use_priv);
>>
>>      pp_pics = calloc(requested_count, sizeof(picture_t));
>>
>> @@ -891,7 +903,7 @@ static void SubtitleGetDirtyBounds(vout_display_t *vd,
>>      if (!sys->p_sub_buffer_bounds
>>       || sys->p_sub_buffer_bounds[i].p_pixels == NULL) {
>>          buffer_bounds *p_bb = realloc(sys->p_sub_buffer_bounds,
>> -                                      (i + 2) * sizeof(buffer_bounds));
>> +                                      (i + 2) * sizeof(buffer_bounds));
>>          if (p_bb) {
>>              sys->p_sub_buffer_bounds = p_bb;
>>              sys->p_sub_buffer_bounds[i].p_pixels =
>> sys->p_sub_pic->p[0].p_pixels;
>> @@ -955,12 +967,12 @@ static picture_pool_t *Pool(vout_display_t *vd,
>> unsigned requested_count)
>>  {
>>      vout_display_sys_t *sys = vd->sys;
>>
>> -    if (!jni_LockAndGetIsSurfaceAttached() && sys->pool != NULL) {
>> +    if (!jni_LockAndGetIsSurfaceAttached(sys->object) && sys->pool !=
>> NULL) {
>>          msg_Dbg(vd, "Surface got destroyed");
>>          picture_pool_Release(sys->pool);
>>          sys->pool = NULL;
>>      }
>> -    jni_UnlockAndroidSurface();
>> +    jni_UnlockAndroidSurface(sys->object);
>>
>>      if (sys->pool == NULL)
>>          sys->pool = PoolAlloc(vd, requested_count);
>> @@ -976,7 +988,7 @@ static void Prepare(vout_display_t *vd, picture_t
>> *picture,
>>      SendEventDisplaySize(vd);
>>
>>      if (subpicture) {
>> -        if (sys->b_sub_invalid) {
>> +         if (sys->b_sub_invalid) {
>>              sys->b_sub_invalid = false;
>>              if (sys->p_sub_pic) {
>>                  picture_Release(sys->p_sub_pic);
>> @@ -990,11 +1002,11 @@ static void Prepare(vout_display_t *vd, picture_t
>> *picture,
>>              sys->p_sub_buffer_bounds = NULL;
>>          }
>>
>> -        if (!jni_LockAndGetIsSurfaceAttached() && sys->p_sub_pic !=
>> NULL) {
>> +        if (!jni_LockAndGetIsSurfaceAttached(sys->object) &&
>> sys->p_sub_pic != NULL) {
>>              picture_Release(sys->p_sub_pic);
>>              sys->p_sub_pic = NULL;
>>          }
>> -        jni_UnlockAndroidSurface();
>> +        jni_UnlockAndroidSurface(sys->object);
>>
>>          if (!sys->p_sub_pic && SetupWindowSubtitleSurface(sys) == 0)
>>              sys->p_sub_pic = PictureAlloc(sys, &sys->p_sub_window->fmt);
>> @@ -1084,7 +1096,7 @@ static int Control(vout_display_t *vd, int query,
>> va_list args)
>>              } else
>>                  CopySourceAspect(&sys->p_window->fmt, source);
>>
>> -            UpdateWindowSize(&sys->p_window->fmt,
>> sys->p_window->b_use_priv);
>> +            UpdateWindowSize(sys, &sys->p_window->fmt,
>> sys->p_window->b_use_priv);
>>          } else {
>>              const vout_display_cfg_t *cfg;
>>
>> diff --git a/modules/video_output/android/nativewindow.c
>> b/modules/video_output/android/nativewindow.c
>> index 98c03fa..584bdec 100644
>> --- a/modules/video_output/android/nativewindow.c
>> +++ b/modules/video_output/android/nativewindow.c
>> @@ -40,9 +40,9 @@
>>  #define THREAD_NAME "ANativeWindow"
>>  extern int jni_attach_thread(JNIEnv **env, const char *thread_name);
>>  extern void jni_detach_thread();
>> -extern jobject jni_LockAndGetAndroidJavaSurface();
>> -extern void jni_UnlockAndroidSurface();
>> -extern void  jni_SetSurfaceLayout(int width, int height, int
>> visible_width, int visible_height, int sar_num, int sar_den);
>> +extern jobject jni_LockAndGetAndroidJavaSurface(android_surf_value_t
>> *object);
>> +extern void jni_UnlockAndroidSurface(android_surf_value_t *object);
>> +extern void  jni_SetSurfaceLayout(android_surf_value_t *object, int
>> width, int height, int visible_width, int visible_height, int sar_num, int
>> sar_den);
>>
>>  static int Open(vout_window_t *, const vout_window_cfg_t *);
>>  static void Close(vout_window_t *);
>> @@ -90,7 +90,7 @@ static int Open(vout_window_t *wnd, const
>> vout_window_cfg_t *cfg)
>>      }
>>
>>      // Create the native window by first getting the Java surface.
>> -    jobject javaSurface = jni_LockAndGetAndroidJavaSurface();
>> +    jobject javaSurface = jni_LockAndGetAndroidJavaSurface(NULL);
>>      if (javaSurface == NULL)
>>          goto error;
>>
>> @@ -99,7 +99,7 @@ static int Open(vout_window_t *wnd, const
>> vout_window_cfg_t *cfg)
>>      p_sys->window = p_sys->native_window.winFromSurface(p_env,
>> javaSurface); // ANativeWindow_fromSurface call.
>>      jni_detach_thread();
>>
>> -    jni_UnlockAndroidSurface();
>> +    jni_UnlockAndroidSurface(NULL);
>>
>>      if (p_sys->window == NULL)
>>          goto error;
>> @@ -110,7 +110,7 @@ static int Open(vout_window_t *wnd, const
>> vout_window_cfg_t *cfg)
>>      wnd->sys = p_sys;
>>
>>      // Set the Java surface size.
>> -    jni_SetSurfaceLayout(cfg->width, cfg->height, cfg->width,
>> cfg->height, 1, 1);
>> +    jni_SetSurfaceLayout(NULL, cfg->width, cfg->height, cfg->width,
>> cfg->height, 1, 1);
>>
>>      return VLC_SUCCESS;
>>
>> @@ -144,7 +144,7 @@ static int Control(vout_window_t *wnd, int cmd,
>> va_list ap)
>>          {
>>              unsigned width = va_arg(ap, unsigned);
>>              unsigned height = va_arg(ap, unsigned);
>> -            jni_SetSurfaceLayout(width, height, width, height, 1, 1);
>> +            jni_SetSurfaceLayout(NULL, width, height, width, height, 1,
>> 1);
>>              break;
>>          }
>>          case VOUT_WINDOW_SET_STATE:
>> diff --git a/modules/video_output/android/surface.c
>> b/modules/video_output/android/surface.c
>> index 5ccb102..a07f2eb 100644
>> --- a/modules/video_output/android/surface.c
>> +++ b/modules/video_output/android/surface.c
>> @@ -76,12 +76,15 @@ vlc_module_end()
>>  #define THREAD_NAME "AndroidSurface"
>>  extern int jni_attach_thread(JNIEnv **env, const char *thread_name);
>>  extern void jni_detach_thread();
>> -extern jobject jni_LockAndGetAndroidJavaSurface();
>> -extern void  jni_UnlockAndroidSurface();
>> -extern bool  jni_LockAndGetIsSurfaceAttached();
>> -extern void *jni_AndroidJavaSurfaceToNativeSurface(jobject *surf);
>> -extern void  jni_SetSurfaceLayout(int width, int height, int
>> visible_width, int visible_height, int sar_num, int sar_den);
>> -extern int jni_ConfigureSurface(jobject jsurf, int width, int height,
>> int hal, bool *configured);
>> +
>> +extern jobject jni_LockAndGetAndroidJavaSurface(android_surf_value_t
>> *object);
>> +
>> +extern void  jni_UnlockAndroidSurface(android_surf_value_t *object);
>> +extern bool  jni_LockAndGetIsSurfaceAttached(android_surf_value_t
>> *object);
>> +extern void *jni_AndroidJavaSurfaceToNativeSurface(jobject surf);
>> +
>> +extern void  jni_SetSurfaceLayout(android_surf_value_t *object, int
>> width, int height, int visible_width, int visible_height, int sar_num, int
>> sar_den);
>> +extern int jni_ConfigureSurface(android_surf_value_t *object, int width,
>> int height, int hal, bool *configured);
>>
>>  // _ZN7android7Surface4lockEPNS0_11SurfaceInfoEb
>>  typedef void (*Surface_lock)(void *, void *, int);
>> @@ -125,6 +128,8 @@ struct vout_display_sys_t {
>>      unsigned int i_alloc_height;
>>
>>      video_format_t fmt;
>> +
>> +    android_surf_value_t *object;
>>  };
>>
>>  struct picture_sys_t {
>> @@ -187,7 +192,8 @@ static void UpdateLayout(vout_display_sys_t *sys)
>>          i_height = sys->fmt.i_height;
>>      }
>>
>> -    jni_SetSurfaceLayout(i_width, i_height,
>> +    jni_SetSurfaceLayout(sys->object,
>> +                         i_width, i_height,
>>                           sys->fmt.i_visible_width,
>>                           sys->fmt.i_visible_height,
>>                           i_sar_num,
>> @@ -210,6 +216,13 @@ static int Open(vlc_object_t *p_this)
>>      if (!sys)
>>          goto error;
>>
>> +    sys->object = var_CreateGetAddress (vd, "drawable-androidobject");
>> +    if (!sys->object) {
>> +        free(sys);
>> +        msg_Err(vd, "No android_surf_value_t set.");
>> +        return VLC_EGENERIC;
>> +    }
>> +
>>      /* */
>>      sys->p_library = InitLibrary(sys);
>>      if (!sys->p_library) {
>> @@ -305,6 +318,8 @@ static void Close(vlc_object_t *p_this)
>>      vout_display_t *vd = (vout_display_t *)p_this;
>>      vout_display_sys_t *sys = vd->sys;
>>
>> +    var_Destroy (vd, "drawable-androidobject");
>> +
>>      if (sys) {
>>          if (sys->pool)
>>              picture_pool_Release(sys->pool);
>> @@ -329,11 +344,11 @@ static int  AndroidLockSurface(picture_t *picture)
>>      uint32_t sw, sh;
>>
>>      if (!sys->native_surface) {
>> -        picsys->surf = jni_LockAndGetAndroidJavaSurface();
>> +        picsys->surf = jni_LockAndGetAndroidJavaSurface(sys->object);
>>          if (unlikely(!picsys->surf))
>>              goto error;
>>          sys->native_surface =
>> jni_AndroidJavaSurfaceToNativeSurface(picsys->surf);
>> -        jni_UnlockAndroidSurface();
>> +        jni_UnlockAndroidSurface(sys->object);
>>
>>          if (!sys->native_surface)
>>              return VLC_EGENERIC;
>> @@ -347,7 +362,7 @@ static int  AndroidLockSurface(picture_t *picture)
>>
>>      if (aligned_width != sys->i_alloc_width || sh !=
>> sys->i_alloc_height) {
>>          bool configured;
>> -        if (jni_ConfigureSurface(picsys->surf,
>> +        if (jni_ConfigureSurface(sys->object,
>>                                   aligned_width,
>>                                   sh,
>>                                   sys->i_android_hal,
>> @@ -360,7 +375,7 @@ static int  AndroidLockSurface(picture_t *picture)
>>          UpdateLayout(sys);
>>      }
>>
>> -    if (!jni_LockAndGetIsSurfaceAttached()) {
>> +    if (!jni_LockAndGetIsSurfaceAttached(sys->object)) {
>>          sys->native_surface = NULL;
>>          goto error;
>>      }
>> @@ -372,10 +387,10 @@ static int  AndroidLockSurface(picture_t *picture)
>>
>>      if (info->w != sys->i_alloc_width || info->h != sh) {
>>          sys->s_unlockAndPost(sys->native_surface);
>> -        goto error;
>> +        return VLC_EGENERIC;
>>      }
>>
>> -    jni_UnlockAndroidSurface();
>> +    jni_UnlockAndroidSurface(sys->object);
>>
>>      picture->p[0].p_pixels = (uint8_t*)info->bits;
>>      picture->p[0].i_lines = info->h;
>> @@ -384,7 +399,7 @@ static int  AndroidLockSurface(picture_t *picture)
>>      return VLC_SUCCESS;
>>
>>  error:
>> -    jni_UnlockAndroidSurface();
>> +    jni_UnlockAndroidSurface(sys->object);
>>      return VLC_EGENERIC;
>>  }
>>
>> @@ -393,9 +408,9 @@ static void AndroidUnlockSurface(picture_t *picture)
>>      picture_sys_t *picsys = picture->p_sys;
>>      vout_display_sys_t *sys = picsys->sys;
>>
>> -    if (jni_LockAndGetIsSurfaceAttached() && sys->native_surface)
>> +    if (jni_LockAndGetIsSurfaceAttached(sys->object) &&
>> sys->native_surface)
>>          sys->s_unlockAndPost(sys->native_surface);
>> -    jni_UnlockAndroidSurface();
>> +    jni_UnlockAndroidSurface(sys->object);
>>  }
>>
>>  static void Display(vout_display_t *vd, picture_t *picture, subpicture_t
>> *subpicture)
>> diff --git a/modules/video_output/android/utils.h
>> b/modules/video_output/android/utils.h
>> index 96d4f86..dfc4913 100644
>> --- a/modules/video_output/android/utils.h
>> +++ b/modules/video_output/android/utils.h
>> @@ -24,6 +24,7 @@
>>  # include "config.h"
>>  #endif
>>
>> +#include <pthread.h>
>>  #include <android/native_window.h>
>>  #include <jni.h>
>>  #include <android/native_window_jni.h>
>> @@ -46,6 +47,8 @@ typedef struct
>>      ptr_ANativeWindow_setBuffersGeometry setBuffersGeometry;
>>  } native_window_api_t;
>>
>> +typedef struct android_surf_value_t android_surf_value_t;
>> +
>>  /* Fill the structure passed as parameter and return a library handle
>>     that should be destroyed with dlclose. */
>>  void *LoadNativeWindowAPI(native_window_api_t *native);
>> --
>> 1.9.3 (Apple Git-50)
>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20150115/0a131f07/attachment.html>


More information about the vlc-devel mailing list