How to switch GStreamerSurfaceView between two pipelines?

Anton Olegovich ivanushkin.anton.olegovich at gmail.com
Mon Oct 6 09:01:09 PDT 2014


I've got two pipelines:

data->video_pipeline = gst_parse_launch("udpsrc port=5000 
caps=application/x-rtp buffer-size=100000 ! rtph264depay ! ffdec_h264 ! 
clockoverlay time-format=\"%D\n%H:%M:%S\" ! autovideosink sync=false", 
&error);

and another

"udpsrc port=5000 caps=application/x-rtp buffer-size=100000 ! 
rtph264depay  !  tee name=splitter ! ffdec_h264  ! clockoverlay 
time-format=\"%D\n%H:%M:%S\" ! autovideosink sync=false splitter. ! 
queue ! mpegpsmux name=mux ! filesink location=" ( the string appends by 
file location and parses by gst_parse_launch also)

And now i want to combine this two pipelines in one application.
What would i do with GStreamerSurfaceView when desire to switch to 
another pipeline?

How sould i reinitialize Surface to prepare it to work with another pipe 
after setting the first one to Null- or Pause-state.

_The native part of work with Surface:_

/static void gst_native_surface_init (JNIEnv *env, jobject thiz, jobject 
surface) {//
//  CustomData *data = GET_CUSTOM_DATA (env, thiz, custom_data_field_id);//
//  Surface = surface;//
//  if (!data) return;//
//  ANativeWindow *new_native_window = ANativeWindow_fromSurface(env, 
surface);//
//  GST_DEBUG ("Received surface %p (native window %p)", surface, 
new_native_window);//
//
//  if (data->native_window) {//
//    ANativeWindow_release (data->native_window);//
////
//     if (data->native_window == new_native_window) {//
//        GST_DEBUG ("New native window is the same as the previous 
one", data->native_window);//
//      if (data->video_sink) {//
//        gst_x_overlay_expose(GST_X_OVERLAY (data->video_sink));//
//        gst_x_overlay_expose(GST_X_OVERLAY (data->video_sink));//
//      }//
//      return;//
//    } else {//
//      GST_DEBUG ("Released previous native window %p", 
data->native_window);//
//      data->initialized = FALSE;//
//    }//
////
//  }//
//  else data->native_window = new_native_window;//
//
//  check_initialization_complete (data);//
//}//
//
//static void gst_native_surface_finalize (JNIEnv *env, jobject thiz) {//
//  CustomData *data = GET_CUSTOM_DATA (env, thiz, custom_data_field_id);//
//  if (!data) return;//
//  GST_DEBUG ("Releasing Native Window %p", data->native_window);//
//
//  if (data->video_sink) {//
//    gst_x_overlay_set_window_handle (GST_X_OVERLAY (data->video_sink), 
(guintptr)NULL);//
//    gst_element_set_state (data->video_pipeline, GST_STATE_READY);//
//  }//
//
//  ANativeWindow_release (data->native_window);//
//  data->native_window = NULL;//
//  data->initialized = FALSE;//
//}//
/
_The GstreamerSurfaceView class:__
_
/import android.content.Context;//
//import android.util.AttributeSet;//
//import android.util.Log;//
//import android.view.SurfaceView;//
//import android.view.View;//
//
//// A simple SurfaceView whose width and height can be set from the 
outside//
//public class GStreamerSurfaceView extends SurfaceView {//
//    public int media_width = 320;//
//    public int media_height = 240;//
//
//    // Mandatory constructors, they do not do much//
//    public GStreamerSurfaceView(Context context, AttributeSet attrs,//
//            int defStyle) {//
//        super(context, attrs, defStyle);//
//    }//
//
//    public GStreamerSurfaceView(Context context, AttributeSet attrs) {//
//        super(context, attrs);//
//    }//
//
//    public GStreamerSurfaceView (Context context) {//
//        super(context);//
//    }//
//
//    // Called by the layout manager to find out our size and give us 
some rules.//
//    // We will try to maximize our size, and preserve the media's 
aspect ratio if//
//    // we are given the freedom to do so.//
//    @Override//
//    protected void onMeasure(int widthMeasureSpec, int 
heightMeasureSpec) {//
//        int width = 0, height = 0;//
//        int wmode = View.MeasureSpec.getMode(widthMeasureSpec);//
//        int hmode = View.MeasureSpec.getMode(heightMeasureSpec);//
//        int wsize = View.MeasureSpec.getSize(widthMeasureSpec);//
//        int hsize = View.MeasureSpec.getSize(heightMeasureSpec);//
//
//        Log.i ("GStreamer", "onMeasure called with " + media_width + 
"x" + media_height);//
//        // Obey width rules//
//        switch (wmode) {//
//        case View.MeasureSpec.AT_MOST://
//            if (hmode == View.MeasureSpec.EXACTLY) {//
//                width = Math.min(hsize * media_width / media_height, 
wsize);//
//                break;//
//            }//
//        case View.MeasureSpec.EXACTLY://
//            width = wsize;//
//            break;//
//        case View.MeasureSpec.UNSPECIFIED://
//            width = media_width;//
//        }//
//
//        // Obey height rules//
//        switch (hmode) {//
//        case View.MeasureSpec.AT_MOST://
//            if (wmode == View.MeasureSpec.EXACTLY) {//
//                height = Math.min(wsize * media_height / media_width, 
hsize);//
//                break;//
//            }//
//        case View.MeasureSpec.EXACTLY://
//            height = hsize;//
//            break;//
//        case View.MeasureSpec.UNSPECIFIED://
//            height = media_height;//
//        }//
//
//        // Finally, calculate best size when both axis are free//
//        if (hmode == View.MeasureSpec.AT_MOST && wmode == 
View.MeasureSpec.AT_MOST) {//
//            int correct_height = width * media_height / media_width;//
//            int correct_width = height * media_width / media_height;//
//
//            if (correct_height < height)//
//                height = correct_height;//
//            else//
//                width = correct_width;//
//        }//
//
//        // Obey minimum size//
//        width = Math.max (getSuggestedMinimumWidth(), width);//
//        height = Math.max (getSuggestedMinimumHeight(), height);//
//        setMeasuredDimension(width, height);//
//    }//
//
//}/

The MainActivity implements SurfaceHolder.Callback:

/ public void surfaceChanged(SurfaceHolder holder, int format, int width,//
//                int height) {//
//            Log.d("GStreamer", "Surface changed to format " + format + 
" width "//
//                    + width + " height " + height);//
//          /////
////
//            nativeSurfaceInit (holder.getSurface());//
//           nativePlay(); //
//////
//        }//
//
//        public void surfaceCreated(SurfaceHolder holder) {//
//            Log.d("GStreamer", "Surface created: " + 
holder.getSurface());//
//        }//
//
//        public void surfaceDestroyed(SurfaceHolder holder) {//
//            Log.d("GStreamer", "Surface destroyed");//
//           // nativePause();//
//            nativeSurfaceFinalize ();//
//        }//
//
/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/gstreamer-devel/attachments/20141006/93ab8510/attachment-0001.html>


More information about the gstreamer-devel mailing list