Regarding buffer size

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

Regarding buffer size

Shilpa Chandrappa
Hi,

I am receiving rtsp video streams(video format: H264) to buffer using appsink. To confirm whether data is received correctly I wrote the data from buffer to a file and file played successfully. But when I am printing the size of buffer I am getting lot of variation. Could anyone explain what this size refers to ? Is this frame size of h264 data ?


Code snippet to print the Buffer size .
==========================


Appsink Pull Buffer Code

static void new_buffer (GstElement *sink, CustomData *data) {
  GstBuffer *buffer;

    g_signal_emit_by_name (sink, "pull-buffer", &buffer);
    if (buffer) {

      gint size=GST_BUFFER_SIZE(buffer);
      g_print("\nsize=%d \n",size);

      fwrite(GST_BUFFER_DATA(buffer), 1, GST_BUFFER_SIZE(buffer),data->fp);

      gst_buffer_unref (buffer);
   }
}

==========================

Result
==========================
size=74037

size=15268

size=12435

size=11429

size=11687

size=11056

size=10762

size=10938

size=10400

size=10569

size=10409

size=10134

size=10098

size=10193

size=10191

size=9934

size=10143

size=10070

size=9880

size=9834

size=9576

size=9804

size=10188

size=9576

size=9835

size=10203

size=10203

size=10153

size=9807

size=9781

size=55

size=8

==========================


Thanks,
Shilpa
Reply | Threaded
Open this post in threaded view
|

Re: Regarding buffer size

Sebastian Dröge-3
On Do, 2014-01-02 at 06:43 -0800, Shilpa Chandrappa wrote:
> Hi,
>
> I am receiving rtsp video streams(video format: H264) to buffer using
> appsink. To confirm whether data is received correctly I wrote the data from
> buffer to a file and file played successfully. But when I am printing the
> size of buffer I am getting lot of variation. Could anyone explain what this
> size refers to ? Is this frame size of h264 data ?

It's the number of bytes in the buffers you receive there. What that
means depends on the caps on the appsink sinkpad. It could be one H264
AU per buffer.

--
Sebastian Dröge, Centricular Ltd - http://www.centricular.com
Expertise, Straight from the Source

_______________________________________________
gstreamer-devel mailing list
[hidden email]
http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel

signature.asc (985 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Regarding buffer size

Shilpa Chandrappa
Thank you.

I want to receive 8192 Bytes every time and pass it on to a API for some processing. API will process on 8192 Bytes each time.

How to pull 8192 Bytes every time? I tried with blocksize option in appsink, but I don't see any change.


Thanks,
Shilpa Chandrappa
Reply | Threaded
Open this post in threaded view
|

Re: Regarding buffer size

Sebastian Dröge-3
On Fr, 2014-01-03 at 04:14 -0800, Shilpa Chandrappa wrote:
> Thank you.
>
> I want to receive 8192 Bytes every time and pass it on to a API for some
> processing. API will process on 8192 Bytes each time.
>
> How to pull 8192 Bytes every time? I tried with blocksize option in appsink,
> but I don't see any change.

Use an GstAdapter into which you put all buffers, and then do a loop
like and in there pull chunks of 8192 bytes from the adapter.

--
Sebastian Dröge, Centricular Ltd - http://www.centricular.com
Expertise, Straight from the Source

_______________________________________________
gstreamer-devel mailing list
[hidden email]
http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel

signature.asc (985 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Regarding buffer size

Shilpa Chandrappa
This post was updated on .
I am looking into GstAdapter. I couldn't find any sample code, so starting it from the beginning. I declared GStAdapter  and did compilation(Please refer to code below).

I am getting below message after compilation.

undefined reference to `gst_adapter_new'
collect2: error: ld returned 1 exit status



static void new_buffer (GstElement *sink, CustomData *data) {
  GstBuffer *buffer;

  GstAdapter *adapter;
  adapter = gst_adapter_new();

   g_signal_emit_by_name (sink, "pull-buffer", &buffer);
   if (buffer) {

    gint size=GST_BUFFER_SIZE(buffer);
    g_print("\nsize=%d \n",size);


    fwrite(GST_BUFFER_DATA(buffer), 1, GST_BUFFER_SIZE(buffer),data->fp);
    gst_buffer_unref (buffer);
  }
}

Am I declaring GstAdapter in wrong way ? It would be helpful if you could share a sample code.

Thanks,
Shilpa Chandrappa
Reply | Threaded
Open this post in threaded view
|

Re: Regarding buffer size

Sebastian Dröge-3
On Fr, 2014-01-03 at 05:07 -0800, Shilpa Chandrappa wrote:
> I am looking into GstAdapter. I couldn't find any sample code, so starting it
> from the beginning. I declared GStAdapter  and did compilation(Please refer
> to code below).
>
> I am getting t below message after compilation.
> *
> undefined reference to `gst_adapter_new'
> collect2: error: ld returned 1 exit status*

You need to link with libgstbase.

Also check the GStreamer plugin sources, there are hundreds of examples
that use GstAdapter.

--
Sebastian Dröge, Centricular Ltd - http://www.centricular.com
Expertise, Straight from the Source

_______________________________________________
gstreamer-devel mailing list
[hidden email]
http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel

signature.asc (985 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Regarding buffer size

Sebastian Dröge-3
On Fr, 2014-01-03 at 16:51 +0100, Sebastian Dröge wrote:

> On Fr, 2014-01-03 at 05:07 -0800, Shilpa Chandrappa wrote:
> > I am looking into GstAdapter. I couldn't find any sample code, so starting it
> > from the beginning. I declared GStAdapter  and did compilation(Please refer
> > to code below).
> >
> > I am getting t below message after compilation.
> > *
> > undefined reference to `gst_adapter_new'
> > collect2: error: ld returned 1 exit status*
>
> You need to link with libgstbase.
>
> Also check the GStreamer plugin sources, there are hundreds of examples
> that use GstAdapter.
And also one at the top of the documentation here:
http://gstreamer.freedesktop.org/data/doc/gstreamer/head/gstreamer-libs/html/GstAdapter.html

--
Sebastian Dröge, Centricular Ltd - http://www.centricular.com
Expertise, Straight from the Source

_______________________________________________
gstreamer-devel mailing list
[hidden email]
http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel

signature.asc (985 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Regarding buffer size

Shilpa Chandrappa
Linking libgstbase solved the issue.

I am able to receive chunks of data. In the below code I am pulling 8192 Bytes of data every time. If size is less than this, Looks like function is dropping the data. How to manage, not to drop any data ?  And also I cant pass < 8192Bytes to  API function.


static void new_buffer (GstElement *sink, CustomData *data) {
  GstBuffer *buffer;
  GstAdapter *adapter;
  const guint8 *data1;

  GstFlowReturn ret = GST_FLOW_OK;
  adapter = gst_adapter_new();
  g_signal_emit_by_name (sink, "pull-buffer", &buffer);
  if (buffer) {

    gint size=GST_BUFFER_SIZE(buffer);
    g_print("\nsize=%d \n",GST_BUFFER_SIZE(buffer));

    gst_adapter_push (adapter, buffer);


    printf("fwrite  %d\n",fwrite(GST_BUFFER_DATA(buffer), 1, GST_BUFFER_SIZE(buffer),data->fp));

    while (gst_adapter_available (adapter) >= 8192 )
    {
       data1 = gst_adapter_peek (adapter,8192);
       gst_adapter_flush (adapter, 8192);
       API(data1,8192);
    }
   
     gst_buffer_unref (buffer);
  }
}

Thanks,
Shilpa
Reply | Threaded
Open this post in threaded view
|

Re: Regarding buffer size

Sebastian Dröge-3
On Mo, 2014-01-06 at 04:26 -0800, Shilpa Chandrappa wrote:
> Linking libgstbase solved the issue.
>
> I am able to receive chunks of data. In the below code I am pulling 8192
> Bytes of data every time. If size is less than this, Looks like function is
> dropping the data. How to manage, not to drop any data ?

Allocate the adapter in a central place. Currently you allocate it once
per buffer, of course it "drops" the data between each callback then.

> And also I cant pass < 8192Bytes to  API function.

Well, if you can also pass less than that to the API, adjust the loop
accordingly to pull out as much as is available but at maximum 8192
bytes. Using an adapter in that case is probably not ideal, you could
just have a loop without an adapter for that.

--
Sebastian Dröge, Centricular Ltd - http://www.centricular.com
Expertise, Straight from the Source

_______________________________________________
gstreamer-devel mailing list
[hidden email]
http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel

signature.asc (985 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Regarding buffer size

Shilpa Chandrappa
Reg "Allocate the adapter in a central place. Currently you allocate it once
per buffer, of course it "drops" the data between each callback then. "

Sorry, I am not able to get you. Could you please explain more on this.

Reg "> And also I cant pass < 8192Bytes to  API function.

Well, if you can also pass less than that to the API, adjust the loop
accordingly to pull out as much as is available but at maximum 8192
bytes. Using an adapter in that case is probably not ideal, you could
just have a loop without an adapter for that. "

I meant I can't pass <8192.

Thanks,
Shilpa