Why I cant't in other thread to get buffer from appsink ??????????????

DBOYaoao yiikai1987910 at gmail.com
Wed Jun 12 21:18:48 PDT 2013


HI ALL:
      I use appsink to get a frmae of film picture,when I use new-buffer
signal that no problem,but when I use
g_signal_emit_by_name(videosink,"pull-buffer",&buffer,NULL) in other thread,  
When I write buffer->data in local file there are all 0.   can anyone help
me ????

CODE:

void* ctl(void* arg)
{
    printf("other thread\n");
    while(1)
    {
        char x = getchar();
        switch(x)
        {
        case 'p':
        {
            GstBuffer* buffer;
            g_signal_emit_by_name(videosink,"pull-buffer",&buffer,NULL);
            const char *tmp = gst_caps_to_string((GST_BUFFER_CAPS(buffer)));


            printf("%s\n",tmp);
            FILE *f = fopen("save.yuv","wb");
            if(!f)
            {
                printf("open file error\n");
                return 0;
            }
            fwrite(buffer->data,1,buffer->size,f);

            fclose(f);
        }break;
        default:break;
        }
    }
}

int main(int argc,char **argv)
{
    gst_init(&argc,&argv);
    loop = g_main_loop_new (NULL, FALSE);


    pipeline = gst_pipeline_new("video-player");
    src = gst_element_factory_make ("filesrc", "file-source");
    decode = gst_element_factory_make("decodebin2","decode");
    videosink = gst_element_factory_make("appsink","video-sink");
    g_signal_connect(videosink,"new-buffer",G_CALLBACK(appsinkCB),NULL);
    g_object_set(videosink, "emit-signals", TRUE);
    audiosink = gst_element_factory_make("alsasink","audio-sink");
    if(!pipeline || !src || !decode || !videosink || !audiosink)
    {
        printf("create element error\n");
        return 0;
    }
    bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
    gst_bus_add_watch (bus, bus_call, loop);
    gst_object_unref (bus);
    g_object_set (G_OBJECT (src), "location", argv[1], NULL);
    g_signal_connect (decode, "pad-added", G_CALLBACK (user_function),
NULL);
    gst_bin_add_many (GST_BIN (pipeline), src,
decode,videosink,audiosink,NULL);
    gst_element_link(src,decode);

    gst_element_set_state (pipeline, GST_STATE_PLAYING);
    pthread_create(&tid,NULL,ctl,NULL);
    g_main_loop_run (loop);

    return 0;
}

THANKS!!!



--
View this message in context: http://gstreamer-devel.966125.n4.nabble.com/Why-I-cant-t-in-other-thread-to-get-buffer-from-appsink-tp4660537.html
Sent from the GStreamer-devel mailing list archive at Nabble.com.


More information about the gstreamer-devel mailing list