problom with constructing GstBuffer
Ugly Face
xuchangxue365812 at 126.com
Fri Jan 3 05:55:10 PST 2014
I am developping a android program. I need to push NV21 raw video data into
pipeline which will transmit it with rtp. I use appsrc .
code is like this:
static void gst_native_push_data(JNIEnv * env, jobject thiz, jbyteArray
fdata)
{
int data_len = 115200;
int frame_rate = 15;
GstBuffer *buffer;
buffer = gst_buffer_new_and_alloc(data_len);
CustomData *data = GET_CUSTOM_DATA (env, thiz, custom_data_field_id);
GST_BUFFER_TIMESTAMP (buffer) = gst_util_uint64_scale (data->frame_num,
GST_SECOND, frame_rate);
GST_BUFFER_DURATION (buffer) = gst_util_uint64_scale (1, GST_SECOND,
frame_rate);
data->frame_num++;
GST_BUFFER_DATA (buffer) = (*env)->GetByteArrayElements(env, fdata,
JNI_FALSE);
gst_app_src_push_buffer(data->appsrc, buffer);
gst_buffer_unref(buffer);
}
with error like this :gstvideorate.c:830:gst_video_rate_event:<videorate>
Got segment but doesn't have GST_FORMAT_TIME value
I think I did not construct a Gstbuffer properly and I don't kwon what dose
this message mean.
code:
static void *app_function(CustomData *userdata)
{
gboolean res;
GstPadLinkReturn linkres;
GstCaps *caps;
CustomData *data = (CustomData *)userdata;
GstPad *srcpad;
GstPad *sinkpad;
GstElement *rtpbin; // rtpbin to get rtp work.
GstElement *queue;
GstElement *videorate; // to deal with timestamps.
GstElement *videoconv;
GstElement *x264encoder;// encode the raw data.
GstElement *rtph264pay; // packetize the encoded data.
GstElement *rtpsink;
GstElement *rtcpsink;
GstElement *rtcpsrc;
gst_init(NULL, NULL);
data->pipeline = gst_pipeline_new(NULL);
g_assert(data->pipeline);
data->appsrc= gst_element_factory_make("appsrc", "appsrc");
g_assert(data->appsrc);
g_object_set(data->appsrc, "is-live", TRUE, NULL);
caps = gst_caps_from_string(CAPS);
g_object_set(data->appsrc, "caps", caps, NULL);
queue = gst_element_factory_make("queue", "queue");
g_assert(queue);
videorate = gst_element_factory_make("videorate", "videorate");
g_assert(videorate);
videoconv = gst_element_factory_make("ffmpegcolorspace", "videoconv");
g_assert(videoconv);
x264encoder = gst_element_factory_make("x264enc", "x264encoder");
g_assert(x264encoder);
g_object_set(x264encoder, "byte-stream", TRUE, "bitrate",
300,"speed-preset", 2, NULL);
rtph264pay = gst_element_factory_make("rtph264pay", "rtph264pay");
g_assert(rtph264pay);
g_object_set(rtph264pay, "config-interval", 2, NULL);
rtpsink = gst_element_factory_make("udpsink", "rtpsink");
g_assert(rtpsink);
g_object_set(rtpsink, "port", RTPPORT, "host", REMOTEIP,"ts-offset", 0,
NULL);
rtcpsink = gst_element_factory_make("udpsink", "rtcpsink");
g_assert(rtcpsink);
g_object_set(rtcpsink, "port", RTCPOUTPORT, "host", REMOTEIP, "sync",
FALSE, "async", FALSE, NULL);
rtcpsrc = gst_element_factory_make("udpsrc", "rtcpsrc");
g_assert(rtcpsrc);
g_object_set(rtcpsrc, "port", RTCPINPORT, NULL);
rtpbin = gst_element_factory_make("gstrtpbin", "rtpbin");
g_assert(rtpbin);
__android_log_print (ANDROID_LOG_ERROR, "camera_gst_codec", "elements make
finished!");
gst_bin_add_many(GST_BIN(data->pipeline), data->appsrc, queue, videorate,
videoconv, x264encoder,rtph264pay,
rtpsink, rtcpsink, rtcpsrc, rtpbin, NULL);
res=gst_element_link(data->appsrc, queue);
g_assert(res);
res=gst_element_link(queue, videorate);
g_assert(res);
res=gst_element_link(videorate, videoconv);
g_assert(res);
res=gst_element_link(videoconv, x264encoder);
g_assert(res);
res=gst_element_link(x264encoder, rtph264pay);
g_assert(res);
srcpad = gst_element_get_static_pad(rtph264pay, "src");
sinkpad = gst_element_get_request_pad(rtpbin, "send_rtp_sink_0");
linkres = gst_pad_link(srcpad, sinkpad);
g_assert(GST_PAD_LINK_OK == linkres);
g_object_unref(srcpad);
// lead rtp stream out of rtpbin via udpsink
srcpad = gst_element_get_static_pad(rtpbin, "send_rtp_src_0");
sinkpad = gst_element_get_static_pad(rtpsink, "sink");
linkres = gst_pad_link(srcpad, sinkpad);
g_assert(GST_PAD_LINK_OK == linkres);
g_object_unref(srcpad);
g_object_unref(sinkpad);
// let rtcp stream into rtpbin via udpsrc.
srcpad = gst_element_get_static_pad(rtcpsrc, "src");
sinkpad = gst_element_get_request_pad(rtpbin, "recv_rtcp_sink_0");
linkres = gst_pad_link(srcpad, sinkpad);
g_assert(GST_PAD_LINK_OK == linkres);
g_object_unref(srcpad);
// lead rtcp stream out of rtpbin via udpsink.
srcpad = gst_element_get_request_pad(rtpbin, "send_rtcp_src_0");
sinkpad = gst_element_get_static_pad(rtcpsink, "sink");
linkres = gst_pad_link(srcpad, sinkpad);
g_assert(GST_PAD_LINK_OK == linkres);
g_object_unref(sinkpad);
g_print ("starting sender pipeline\n");
gst_element_set_state (data->pipeline, GST_STATE_PLAYING);
data->main_loop = g_main_loop_new (NULL, FALSE);
g_main_loop_run (data->main_loop);
gst_element_set_state (data->pipeline, GST_STATE_NULL);
gst_object_unref(GST_OBJECT(data->pipeline));
}
with warning log like this:
01-03 21:51:03.750: W/GStreamer+bin(3310): 0:00:11.178009032 0x58faf9a0
gstbin.c:2399:gst_bin_do_latency_func:<pipeline0> failed to query latency
I do not know what is the meaning od this .
at last , the program fail with :
01-03 21:54:08.414: A/libc(3310): Fatal signal 11 (SIGSEGV) at 0x00000018
(code=1), thread 3332 (appsrc:src)
Thanks in advance.
Gorge
--
View this message in context: http://gstreamer-devel.966125.n4.nabble.com/problom-with-constructing-GstBuffer-tp4664432.html
Sent from the GStreamer-devel mailing list archive at Nabble.com.
More information about the gstreamer-devel
mailing list