how appsrc work ?

joao machado 00jmsmachado at gmail.com
Thu Jul 2 05:03:28 PDT 2015


Hi.

I did something similar in the past but did not finish in the receiver
side, therefore I do not have guaranties if it is the publisher or the
receiver that have the issue, The only guarantee I have is that the buffers
are transfered and the sizes are corente in the receiver side.


    size_t size;
           GstMemory *memory;
            GstMapInfo info;


                    /* allocate memory and add to the buffer */
        size = samples[i].payload.length();
buffer = gst_buffer_new_and_alloc(size);
   //std::cout << "Payload size " << size << std::endl;
memory = gst_allocator_alloc (NULL, size, NULL);
        gst_buffer_append_memory (buffer, memory);
        /* get WRITE access to the memory and copy image */
        gst_buffer_map (buffer, &info, GST_MAP_WRITE);
                        //std::cout << "Memory copy before" << std::endl;
//memcpy(buffer, (void*)samples[i].payload[0], size);
                        int j;
        for (j = 0; j < size; j++){
*((char *) info.data + j) = samples[i].payload[j];
 }
//std::cout << "Memory copy after" << std::endl;
        gst_buffer_unmap (buffer, &info);

            //pthread_mutex_lock(&mutex);
// myBufferDeque.push_back(buffer);
//pthread_mutex_unlock(&mutex);
  printf("pushing buffer: %s\n",gst_flow_get_name (
        gst_app_src_push_buffer (GST_APP_SRC (source), buffer)
          ))
          ;

                }
            }


In the receiver side you need something like the following code


GstAppSink *sink,

  /* Retrieve the buffer */
  GstSample *gst_sample = gst_app_sink_pull_sample(sink);
  if (NULL == gst_sample) {
g_warning("error getting Gstreamer sample");
  } else {
  buffer = gst_sample_get_buffer(gst_sample);
  if(buffer != NULL) {
GstMapInfo bufferInfo;
gst_buffer_map(buffer, &bufferInfo, GST_MAP_READ);
g_print ("**** nsize=%d ***** ", bufferInfo.size);
//bufferInfo.data
//Todo: copy data to the sample or use loan buffers
if (bufferInfo.size < data->payloadSize) {
(*(data->sample)).payload.length(bufferInfo.size);
for(unsigned long j = 0; j < bufferInfo.size; j++)
{
 //data->sample[j] = bufferInfo.data[j];
 (*(data->sample)).payload[j] = bufferInfo.data[j];
}

data->sample->count++;
std::cout<< "count [" << data->sample->count << "]" << std::endl;
status = data->e->writer->write(*(data->sample), *(data->handle));
CHECK_STATUS_MACRO(status);
  } else {
g_print ("**** BUFFER SIZE IS TOO HIGH %d ***** ", bufferInfo.size);
}
 gst_buffer_unmap(buffer, &bufferInfo);
        }
gst_sample_unref(gst_sample);
  }

  return GST_FLOW_OK;



We can work this out together in the near future and hope the  code works
for your needs.

Regards,
JoaoM.

On Thu, Jul 2, 2015 at 11:36 AM, vkcorp <vkcorp at naver.com> wrote:

> I'm trying to check appsrc's code to track how it works.
> I usually call gst_app_src_push_buffer() to feed it,
> but I can't find it to transfer next elements on pipeline.
>
> I guess appsrc receive buffer and provide it to next element.
>
> I just found gst_app_src_create() function but it just pop out buffer from
> queue
> and wouldn't send it to next element.
> Actually I expected some kind of push_buffer() kinds of functions on it.
>
> Are there any push functions on appsrc inside ?
> Or maybe on basesrc ?
>
>
>
>
> --
> View this message in context:
> http://gstreamer-devel.966125.n4.nabble.com/how-appsrc-work-tp4672535.html
> Sent from the GStreamer-devel mailing list archive at Nabble.com.
> _______________________________________________
> gstreamer-devel mailing list
> gstreamer-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/gstreamer-devel/attachments/20150702/286dda47/attachment.html>


More information about the gstreamer-devel mailing list