g_signal_emit_by_name(sink, "pull-sample", &sample);
buffer = gst_sample_get_buffer(sample);
- if (buffer) {
- if (gst_buffer_map(buffer, &map, GST_MAP_READ)) {
- if (!GST_BUFFER_FLAG_IS_SET(buffer, GST_BUFFER_FLAG_DELTA_UNIT)) {
- /* g_print( " Key Frame \n"); */
- key = 1;
- } else {
- /* g_print( " NOT a Key Frame \n"); */
- key = 0;
- }
- if (media_format_create(&audfmt)) {
- g_print("media_format_create failed\n");
- gst_buffer_unmap(buffer, &map);
- return;
- }
+ if (!buffer) {
+ g_print("__audio_app_sink_callback buffer is NULL");
+ return;
+ }
- g_print("audio data_sink = %s\n", data_sink);
- /* check if the mime selected during set_data_sink is matching with the mime of the file inputted.*/
- if (g_str_has_prefix(new_pad_type_aud, "audio/mpeg")
- && (strncmp(data_sink, "11", 2) == 0 || strncmp(data_sink, "12", 2) == 0 || strncmp(data_sink, "13", 2) == 0
- || strncmp(data_sink, "21", 2) == 0 || strncmp(data_sink, "22", 2) == 0)) {
- if (media_format_set_audio_mime(audfmt, MEDIA_FORMAT_AAC_LC)) {
- g_print("media_format_set_audio_mime failed\n");
- goto ERROR1;
- }
- } else if (g_str_has_prefix(new_pad_type_aud, "audio/AMR-WB")
- && strncmp(data_sink, "42", 2) == 0) {
- g_print("For amr-wb, setting encoded media type as MEDIA_FORMAT_AMR_WB\n");
- if (media_format_set_audio_mime(audfmt, MEDIA_FORMAT_AMR_WB)) {
- g_print("media_format_set_audio_mime failed\n");
- goto ERROR1;
- }
- } else if (g_str_has_prefix(new_pad_type_aud, "audio/AMR")
- && (strncmp(data_sink, "23", 2) == 0 || strncmp(data_sink, "24", 2) == 0
- || strncmp(data_sink, "41", 2) == 0)) {
- g_print("For amr-nb, setting encoded media type as MEDIA_FORMAT_AMR_NB\n");
- if (media_format_set_audio_mime(audfmt, MEDIA_FORMAT_AMR_NB)) {
- g_print("media_format_set_audio_mime failed\n");
- goto ERROR1;
- }
- } else if (g_str_has_prefix(new_pad_type_aud, "audio/x-wav")
- && strncmp(data_sink, "31", 2) == 0) {
- g_print("creating audio-wav\n");
- if (media_format_set_audio_mime(audfmt, MEDIA_FORMAT_PCM)) {
- g_print("media_format_set_audio_mime failed\n");
- goto ERROR1;
- }
- if (media_format_set_audio_bit(audfmt, 16))
- g_print("wav media_format_set_audio_bit failed\n");
- if (media_format_set_audio_channel(audfmt, 2))
- g_print("wav media_format_set_audio_channel failed\n");
- if (media_format_set_audio_samplerate(audfmt, 44100))
- g_print("wav media_format_set_audio_samplerate failed\n");
- } else
- g_print("Unsupported audio mime\n");
-
- if (media_packet_create(audfmt, NULL, NULL, &aud_pkt)) {
- g_print("create audio media_packet failed\n");
- goto ERROR1;
- }
+ if (!gst_buffer_map(buffer, &map, GST_MAP_READ)) {
+ g_print("__audio_app_sink_callback buffer map is fail");
+ return;
+ }
- if (media_packet_alloc(aud_pkt)) {
- g_print("audio media_packet alloc failed\n");
- goto ERROR2;
- }
+ if (!GST_BUFFER_FLAG_IS_SET(buffer, GST_BUFFER_FLAG_DELTA_UNIT)) {
+ /* g_print( " Key Frame \n"); */
+ key = 1;
+ } else {
+ /* g_print( " NOT a Key Frame \n"); */
+ key = 0;
+ }
- media_packet_get_buffer_data_ptr(aud_pkt, (void **)&dptr);
- memcpy((char*)dptr, map.data, map.size);
+ if (media_format_create(&audfmt)) {
+ g_print("media_format_create failed\n");
+ gst_buffer_unmap(buffer, &map);
+ return;
+ }
- if (media_packet_set_buffer_size(aud_pkt, (uint64_t)(map.size))) {
- g_print("audio set_buffer_size failed\n");
- goto ERROR2;
- }
+ g_print("audio data_sink = %s\n", data_sink);
+ /* check if the mime selected during set_data_sink is matching with the mime of the file inputted.*/
+ if (g_str_has_prefix(new_pad_type_aud, "audio/mpeg")
+ && (strncmp(data_sink, "11", 2) == 0 || strncmp(data_sink, "12", 2) == 0 || strncmp(data_sink, "13", 2) == 0
+ || strncmp(data_sink, "21", 2) == 0 || strncmp(data_sink, "22", 2) == 0)) {
+ if (media_format_set_audio_mime(audfmt, MEDIA_FORMAT_AAC_LC)) {
+ g_print("media_format_set_audio_mime failed\n");
+ goto ERROR1;
+ }
+ } else if (g_str_has_prefix(new_pad_type_aud, "audio/AMR-WB")
+ && strncmp(data_sink, "42", 2) == 0) {
+ g_print("For amr-wb, setting encoded media type as MEDIA_FORMAT_AMR_WB\n");
+ if (media_format_set_audio_mime(audfmt, MEDIA_FORMAT_AMR_WB)) {
+ g_print("media_format_set_audio_mime failed\n");
+ goto ERROR1;
+ }
+ } else if (g_str_has_prefix(new_pad_type_aud, "audio/AMR")
+ && (strncmp(data_sink, "23", 2) == 0 || strncmp(data_sink, "24", 2) == 0
+ || strncmp(data_sink, "41", 2) == 0)) {
+ g_print("For amr-nb, setting encoded media type as MEDIA_FORMAT_AMR_NB\n");
+ if (media_format_set_audio_mime(audfmt, MEDIA_FORMAT_AMR_NB)) {
+ g_print("media_format_set_audio_mime failed\n");
+ goto ERROR1;
+ }
+ } else if (g_str_has_prefix(new_pad_type_aud, "audio/x-wav")
+ && strncmp(data_sink, "31", 2) == 0) {
+ g_print("creating audio-wav\n");
+ if (media_format_set_audio_mime(audfmt, MEDIA_FORMAT_PCM)) {
+ g_print("media_format_set_audio_mime failed\n");
+ goto ERROR1;
+ }
+ if (media_format_set_audio_bit(audfmt, 16))
+ g_print("wav media_format_set_audio_bit failed\n");
+ if (media_format_set_audio_channel(audfmt, 2))
+ g_print("wav media_format_set_audio_channel failed\n");
+ if (media_format_set_audio_samplerate(audfmt, 44100))
+ g_print("wav media_format_set_audio_samplerate failed\n");
+ } else
+ g_print("Unsupported audio mime\n");
+
+ if (media_packet_create(audfmt, NULL, NULL, &aud_pkt)) {
+ g_print("create audio media_packet failed\n");
+ goto ERROR1;
+ }
- if (media_packet_get_buffer_size(aud_pkt, &ns)) {
- g_print("unable to set the buffer size actual =%d, fixed %"PRIu64"\n",
- (unsigned int)map.size, ns);
- goto ERROR2;
- }
+ if (media_packet_alloc(aud_pkt)) {
+ g_print("audio media_packet alloc failed\n");
+ goto ERROR2;
+ }
- if (strncmp(data_sink, "31", 2) == 0 || strncmp(data_sink, "wav", 3) == 0) {
- aud_caps = "audio/x-raw, format=(string)S16LE, layout=(string)interleaved, channels=(int)2, channel-mask=(bitmask)0x0000000000000003, rate=(int)44100";
- /* no need to set the rest of the parameters for wav */
- goto SET_CAPS;
- } else if (strncmp(data_sink, "41", 2) == 0 || strncmp(data_sink, "amr-nb", 6) == 0) {
- /* ToDo: Query caps from amrparse src pad */
- aud_caps = "audio/AMR, channels=1, rate=8000";
- goto SET_CAPS;
- } else if (strncmp(data_sink, "42", 2) == 0 || strncmp(data_sink, "amr-wb", 6) == 0) {
- /* ToDo: Query caps from amrparse src pad */
- aud_caps = "audio/AMR-WB, channels=1, rate=16000";
- goto SET_CAPS;
- }
+ media_packet_get_buffer_data_ptr(aud_pkt, (void **)&dptr);
+ memcpy((char*)dptr, map.data, map.size);
- if (media_packet_set_pts(aud_pkt, buffer->pts)) {
- g_print("unable to set the pts\n");
- goto ERROR2;
- }
+ if (media_packet_set_buffer_size(aud_pkt, (uint64_t)(map.size))) {
+ g_print("audio set_buffer_size failed\n");
+ goto ERROR2;
+ }
- if (media_packet_set_dts(aud_pkt, buffer->dts)) {
- g_print("unable to set the dts\n");
- goto ERROR2;
- }
+ if (media_packet_get_buffer_size(aud_pkt, &ns)) {
+ g_print("unable to set the buffer size actual =%d, fixed %"PRIu64"\n",
+ (unsigned int)map.size, ns);
+ goto ERROR2;
+ }
- if (media_packet_set_duration(aud_pkt, buffer->duration)) {
- g_print("unable to set the duration\n");
- goto ERROR2;
- }
+ if (strncmp(data_sink, "31", 2) == 0 || strncmp(data_sink, "wav", 3) == 0) {
+ aud_caps = "audio/x-raw, format=(string)S16LE, layout=(string)interleaved, channels=(int)2, channel-mask=(bitmask)0x0000000000000003, rate=(int)44100";
+ /* no need to set the rest of the parameters for wav */
+ goto SET_CAPS;
+ } else if (strncmp(data_sink, "41", 2) == 0 || strncmp(data_sink, "amr-nb", 6) == 0) {
+ /* ToDo: Query caps from amrparse src pad */
+ aud_caps = "audio/AMR, channels=1, rate=8000";
+ goto SET_CAPS;
+ } else if (strncmp(data_sink, "42", 2) == 0 || strncmp(data_sink, "amr-wb", 6) == 0) {
+ /* ToDo: Query caps from amrparse src pad */
+ aud_caps = "audio/AMR-WB, channels=1, rate=16000";
+ goto SET_CAPS;
+ }
- if (media_packet_set_flags(aud_pkt, key)) {
- g_print("unable to set the flag size\n");
- goto ERROR2;
- }
+ if (media_packet_set_pts(aud_pkt, buffer->pts)) {
+ g_print("unable to set the pts\n");
+ goto ERROR2;
+ }
+
+ if (media_packet_set_dts(aud_pkt, buffer->dts)) {
+ g_print("unable to set the dts\n");
+ goto ERROR2;
+ }
+
+ if (media_packet_set_duration(aud_pkt, buffer->duration)) {
+ g_print("unable to set the duration\n");
+ goto ERROR2;
+ }
+
+ if (media_packet_set_flags(aud_pkt, key)) {
+ g_print("unable to set the flag size\n");
+ goto ERROR2;
+ }
SET_CAPS:
- if (!aud_codec_data) {
- aud_codec_data = true;
- /* Create the codec data and pass to _gst_copy_buf_to_media_packet() to add into the media packet */
- GstStructure *structure = NULL;
- const GValue *value = NULL;
- GstPad *sink_pad;
- GstCaps *aud_caps;
- GstBuffer *codec_data_buffer = NULL;
- sink_pad = gst_element_get_static_pad(sink, "sink");
- if (!sink_pad) {
- g_print("fail to get audio appsink pad\n");
- goto ERROR2;
- }
-
- aud_caps = gst_pad_get_current_caps(sink_pad);
- structure = gst_caps_get_structure(aud_caps, 0);
- /* get codec data from caps*/
- value = gst_structure_get_value(structure, "codec_data");
- if (value)
- codec_data_buffer = gst_value_get_buffer(value);
-
- if (codec_data_buffer) {
- GstMapInfo codec_data_map;
- if (!gst_buffer_map(codec_data_buffer, &codec_data_map, GST_MAP_READ)) {
- g_print("codec data buffer map failed\n");
- goto ERROR2;
- }
- if (media_packet_set_codec_data(aud_pkt, (void *)codec_data_map.data,
- (unsigned int)codec_data_map.size)) {
- g_print("unable to set the codec data\n");
- gst_buffer_unmap(codec_data_buffer, &codec_data_map);
- goto ERROR2;
- }
- gst_buffer_unmap(codec_data_buffer, &codec_data_map);
-
- media_buffer_flags_e flags;
- media_packet_get_flags(aud_pkt, &flags);
- media_packet_set_flags(aud_pkt, flags | MEDIA_PACKET_CODEC_CONFIG);
- }
- gst_caps_unref(aud_caps);
- }
+ if (!aud_codec_data) {
+ aud_codec_data = true;
+ /* Create the codec data and pass to _gst_copy_buf_to_media_packet() to add into the media packet */
+ GstStructure *structure = NULL;
+ const GValue *value = NULL;
+ GstPad *sink_pad;
+ GstCaps *aud_caps;
+ GstBuffer *codec_data_buffer = NULL;
+ sink_pad = gst_element_get_static_pad(sink, "sink");
+ if (!sink_pad) {
+ g_print("fail to get audio appsink pad\n");
+ goto ERROR2;
+ }
- /* Print count and size to indicate a received buffer */
- g_print("Received audio buffer count : %4d (size : %5"PRIu64", pts : %12"PRIu64")\n",
- ++count, ns, buffer->pts);
- mediamuxer_write_sample(myMuxer, track_index_aud, aud_pkt);
- if (validate_multitrack)
- mediamuxer_write_sample(myMuxer, track_index_aud2, aud_pkt);
+ aud_caps = gst_pad_get_current_caps(sink_pad);
+ structure = gst_caps_get_structure(aud_caps, 0);
+ /* get codec data from caps*/
+ value = gst_structure_get_value(structure, "codec_data");
+ if (value)
+ codec_data_buffer = gst_value_get_buffer(value);
+
+ if (codec_data_buffer) {
+ GstMapInfo codec_data_map;
+ if (!gst_buffer_map(codec_data_buffer, &codec_data_map, GST_MAP_READ)) {
+ g_print("codec data buffer map failed\n");
+ goto ERROR2;
+ }
+ if (media_packet_set_codec_data(aud_pkt, (void *)codec_data_map.data,
+ (unsigned int)codec_data_map.size)) {
+ g_print("unable to set the codec data\n");
+ gst_buffer_unmap(codec_data_buffer, &codec_data_map);
+ goto ERROR2;
+ }
+ gst_buffer_unmap(codec_data_buffer, &codec_data_map);
+ media_buffer_flags_e flags;
+ media_packet_get_flags(aud_pkt, &flags);
+ media_packet_set_flags(aud_pkt, flags | MEDIA_PACKET_CODEC_CONFIG);
}
+ gst_caps_unref(aud_caps);
}
+
+ /* Print count and size to indicate a received buffer */
+ g_print("Received audio buffer count : %4d (size : %5"PRIu64", pts : %12"PRIu64")\n",
+ ++count, ns, buffer->pts);
+ mediamuxer_write_sample(myMuxer, track_index_aud, aud_pkt);
+ if (validate_multitrack)
+ mediamuxer_write_sample(myMuxer, track_index_aud2, aud_pkt);
+
ERROR2:
media_packet_destroy(aud_pkt);
ERROR1:
g_signal_emit_by_name(sink, "pull-sample", &sample);
buffer = gst_sample_get_buffer(sample);
- if (buffer) {
- if (gst_buffer_map(buffer, &map, GST_MAP_READ)) {
- if (media_format_create(&vidfmt)) {
- g_print("media_format_create failed\n");
- gst_buffer_unmap(buffer, &map);
- return;
- }
- g_print("video data_sink = %s\n", data_sink);
-
- /* check if the mime selected during set_data_sink is matching with the mime of the file inputted.*/
- if (g_str_has_prefix(new_pad_type_vid, "video/x-h264")
- && (strncmp(data_sink, "11", 2) == 0
- || strncmp(data_sink, "21", 2) == 0 || strncmp(data_sink, "23", 2) == 0)) {
- if (media_format_set_video_mime(vidfmt, MEDIA_FORMAT_H264_SP)) {
- g_print("media_format_set_video_mime to H264_SP failed\n");
- goto ERROR1;
- }
- } else if (g_str_has_prefix(new_pad_type_vid, "video/mpeg")
- && strncmp(data_sink, "13", 2) == 0) {
- g_print("For mpeg4, setting encoded media type as MEDIA_FORMAT_MPEG4_SP\n");
- if (media_format_set_video_mime(vidfmt, MEDIA_FORMAT_MPEG4_SP)) {
- g_print("media_format_set_video_mime to MPEG4_SP failed\n");
- goto ERROR1;
- }
- } else if (g_str_has_prefix(new_pad_type_vid, "video/x-h263")
- && (strncmp(data_sink, "12", 2) == 0 || strncmp(data_sink, "22", 2) == 0 || strncmp(data_sink, "24", 2) == 0)) {
- g_print("For h263, setting encoded media type as MEDIA_FORMAT_H263\n");
- if (media_format_set_video_mime(vidfmt, MEDIA_FORMAT_H263)) {
- g_print("media_format_set_vidio_mime failed\n");
- goto ERROR1;
- }
- } else
- g_print("Unsupported encoded video mime. Currently muxer supports:h263, h264 & mpeg4\n");
-
- if (!GST_BUFFER_FLAG_IS_SET(buffer, GST_BUFFER_FLAG_DELTA_UNIT)) {
- /* g_print("Key Frame\n"); */
- key = 1;
- } else {
- /* g_print("NOT a Key Frame\n"); */
- key = 0;
- }
+ if (!buffer) {
+ g_print("__video_app_sink_callback buffer is NULL");
+ return;
+ }
- vid_caps_gst = gst_caps_from_string(vid_caps);
- caps_struc = gst_caps_get_structure(vid_caps_gst, 0);
+ if (!gst_buffer_map(buffer, &map, GST_MAP_READ)) {
+ g_print("__video_app_sink_callback buffer map is fail");
+ return;
+ }
- ret = gst_structure_get_int(caps_struc, "width", &video_width);
- ret = ret && gst_structure_get_int(caps_struc, "height", &video_height);
- if (!ret) {
- g_print("Failed to retrive video width/height. returning. \n");
- goto ERROR2;
- }
+ if (media_format_create(&vidfmt)) {
+ g_print("media_format_create failed\n");
+ gst_buffer_unmap(buffer, &map);
+ return;
+ }
+ g_print("video data_sink = %s\n", data_sink);
+
+ /* check if the mime selected during set_data_sink is matching with the mime of the file inputted.*/
+ if (g_str_has_prefix(new_pad_type_vid, "video/x-h264")
+ && (strncmp(data_sink, "11", 2) == 0
+ || strncmp(data_sink, "21", 2) == 0 || strncmp(data_sink, "23", 2) == 0)) {
+ if (media_format_set_video_mime(vidfmt, MEDIA_FORMAT_H264_SP)) {
+ g_print("media_format_set_video_mime to H264_SP failed\n");
+ goto ERROR1;
+ }
+ } else if (g_str_has_prefix(new_pad_type_vid, "video/mpeg")
+ && strncmp(data_sink, "13", 2) == 0) {
+ g_print("For mpeg4, setting encoded media type as MEDIA_FORMAT_MPEG4_SP\n");
+ if (media_format_set_video_mime(vidfmt, MEDIA_FORMAT_MPEG4_SP)) {
+ g_print("media_format_set_video_mime to MPEG4_SP failed\n");
+ goto ERROR1;
+ }
+ } else if (g_str_has_prefix(new_pad_type_vid, "video/x-h263")
+ && (strncmp(data_sink, "12", 2) == 0 || strncmp(data_sink, "22", 2) == 0 || strncmp(data_sink, "24", 2) == 0)) {
+ g_print("For h263, setting encoded media type as MEDIA_FORMAT_H263\n");
+ if (media_format_set_video_mime(vidfmt, MEDIA_FORMAT_H263)) {
+ g_print("media_format_set_vidio_mime failed\n");
+ goto ERROR1;
+ }
+ } else
+ g_print("Unsupported encoded video mime. Currently muxer supports:h263, h264 & mpeg4\n");
- if (count == 0)
- g_print("Extracted width=%d, height=%d\n", video_width, video_height);
- media_format_set_video_width(vidfmt, video_width);
- media_format_set_video_height(vidfmt, video_height);
- /* frame rate is came from the caps filter of demuxer */
- if (media_format_set_video_frame_rate(vidfmt, 30)) {
- g_print("media_format_set_video_frame_rate failed\n");
- goto ERROR2;
- }
+ if (!GST_BUFFER_FLAG_IS_SET(buffer, GST_BUFFER_FLAG_DELTA_UNIT)) {
+ /* g_print("Key Frame\n"); */
+ key = 1;
+ } else {
+ /* g_print("NOT a Key Frame\n"); */
+ key = 0;
+ }
- if (media_packet_create(vidfmt, NULL, NULL, &vid_pkt)) {
- g_print("create video media_packet failed\n");
- goto ERROR2;
- }
+ vid_caps_gst = gst_caps_from_string(vid_caps);
+ caps_struc = gst_caps_get_structure(vid_caps_gst, 0);
- if (media_packet_alloc(vid_pkt)) {
- g_print("video media_packet alloc failed\n");
- goto ERROR3;
- }
+ ret = gst_structure_get_int(caps_struc, "width", &video_width);
+ ret = ret && gst_structure_get_int(caps_struc, "height", &video_height);
+ if (!ret) {
+ g_print("Failed to retrive video width/height. returning. \n");
+ goto ERROR2;
+ }
- media_packet_get_buffer_data_ptr(vid_pkt, (void**)&dptr);
- memcpy((char*)dptr, map.data, map.size);
+ if (count == 0)
+ g_print("Extracted width=%d, height=%d\n", video_width, video_height);
+ media_format_set_video_width(vidfmt, video_width);
+ media_format_set_video_height(vidfmt, video_height);
+ /* frame rate is came from the caps filter of demuxer */
+ if (media_format_set_video_frame_rate(vidfmt, 30)) {
+ g_print("media_format_set_video_frame_rate failed\n");
+ goto ERROR2;
+ }
- if (media_packet_set_buffer_size(vid_pkt, (uint64_t)(map.size))) {
- g_print("video set_buffer_size failed\n");
- goto ERROR3;
- }
+ if (media_packet_create(vidfmt, NULL, NULL, &vid_pkt)) {
+ g_print("create video media_packet failed\n");
+ goto ERROR2;
+ }
- if (media_packet_get_buffer_size(vid_pkt, &ns)) {
- g_print("unable to set the buffer size actual =%d, fixed %"PRIu64"\n",
- (unsigned int)map.size, ns);
- goto ERROR3;
- }
+ if (media_packet_alloc(vid_pkt)) {
+ g_print("video media_packet alloc failed\n");
+ goto ERROR3;
+ }
- if (media_packet_set_pts(vid_pkt, buffer->pts)) {
- g_print("unable to set the pts\n");
- goto ERROR3;
- }
+ media_packet_get_buffer_data_ptr(vid_pkt, (void**)&dptr);
+ memcpy((char*)dptr, map.data, map.size);
- if (media_packet_set_dts(vid_pkt, buffer->dts)) {
- g_print("unable to set the dts\n");
- goto ERROR3;
- }
+ if (media_packet_set_buffer_size(vid_pkt, (uint64_t)(map.size))) {
+ g_print("video set_buffer_size failed\n");
+ goto ERROR3;
+ }
- if (media_packet_set_duration(vid_pkt, buffer->duration)) {
- g_print("unable to set the duration\n");
- goto ERROR3;
- }
+ if (media_packet_get_buffer_size(vid_pkt, &ns)) {
+ g_print("unable to set the buffer size actual =%d, fixed %"PRIu64"\n",
+ (unsigned int)map.size, ns);
+ goto ERROR3;
+ }
- if (media_packet_set_flags(vid_pkt, key)) {
- g_print("unable to set the flag size\n");
- goto ERROR3;
- }
- if (media_packet_set_extra(vid_pkt, vid_caps)) {
- g_print("unable to set the video codec data e\n");
- goto ERROR3;
- }
+ if (media_packet_set_pts(vid_pkt, buffer->pts)) {
+ g_print("unable to set the pts\n");
+ goto ERROR3;
+ }
+
+ if (media_packet_set_dts(vid_pkt, buffer->dts)) {
+ g_print("unable to set the dts\n");
+ goto ERROR3;
+ }
- if (!vid_codec_data) {
- vid_codec_data = true;
- /* Create the codec data and pass to _gst_copy_buf_to_media_packet() to add into the media packet */
- GstStructure *structure = NULL;
- const GValue *value = NULL;
- GstPad *sink_pad;
- GstCaps *vid_caps;
- GstBuffer *codec_data_buffer = NULL;
- sink_pad = gst_element_get_static_pad(sink, "sink");
- if (!sink_pad) {
- g_print("fail to get audio appsink pad\n");
- goto ERROR2;
- }
-
- vid_caps = gst_pad_get_current_caps(sink_pad);
- structure = gst_caps_get_structure(vid_caps, 0);
- /* get codec data from caps*/
- value = gst_structure_get_value(structure, "codec_data");
- if (value)
- codec_data_buffer = gst_value_get_buffer(value);
-
- if (codec_data_buffer) {
- GstMapInfo codec_data_map;
- if (!gst_buffer_map(codec_data_buffer, &codec_data_map, GST_MAP_READ)) {
- g_print("codec data buffer map failed\n");
- goto ERROR2;
- }
- if (media_packet_set_codec_data(vid_pkt, (void *)codec_data_map.data,
- (unsigned int)codec_data_map.size)) {
- g_print("unable to set the codec data\n");
- gst_buffer_unmap(codec_data_buffer, &codec_data_map);
- goto ERROR2;
- }
- gst_buffer_unmap(codec_data_buffer, &codec_data_map);
-
- media_buffer_flags_e flags;
- media_packet_get_flags(vid_pkt, &flags);
- media_packet_set_flags(vid_pkt, flags | MEDIA_PACKET_CODEC_CONFIG);
- }
- gst_caps_unref(vid_caps);
+ if (media_packet_set_duration(vid_pkt, buffer->duration)) {
+ g_print("unable to set the duration\n");
+ goto ERROR3;
+ }
+
+ if (media_packet_set_flags(vid_pkt, key)) {
+ g_print("unable to set the flag size\n");
+ goto ERROR3;
+ }
+ if (media_packet_set_extra(vid_pkt, vid_caps)) {
+ g_print("unable to set the video codec data e\n");
+ goto ERROR3;
+ }
+
+ if (!vid_codec_data) {
+ vid_codec_data = true;
+ /* Create the codec data and pass to _gst_copy_buf_to_media_packet() to add into the media packet */
+ GstStructure *structure = NULL;
+ const GValue *value = NULL;
+ GstPad *sink_pad;
+ GstCaps *vid_caps;
+ GstBuffer *codec_data_buffer = NULL;
+ sink_pad = gst_element_get_static_pad(sink, "sink");
+ if (!sink_pad) {
+ g_print("fail to get audio appsink pad\n");
+ goto ERROR2;
+ }
+
+ vid_caps = gst_pad_get_current_caps(sink_pad);
+ structure = gst_caps_get_structure(vid_caps, 0);
+ /* get codec data from caps*/
+ value = gst_structure_get_value(structure, "codec_data");
+ if (value)
+ codec_data_buffer = gst_value_get_buffer(value);
+
+ if (codec_data_buffer) {
+ GstMapInfo codec_data_map;
+ if (!gst_buffer_map(codec_data_buffer, &codec_data_map, GST_MAP_READ)) {
+ g_print("codec data buffer map failed\n");
+ goto ERROR2;
}
+ if (media_packet_set_codec_data(vid_pkt, (void *)codec_data_map.data,
+ (unsigned int)codec_data_map.size)) {
+ g_print("unable to set the codec data\n");
+ gst_buffer_unmap(codec_data_buffer, &codec_data_map);
+ goto ERROR2;
+ }
+ gst_buffer_unmap(codec_data_buffer, &codec_data_map);
- /* Print count and size to indicate a received buffer */
- g_print("Received video buffer count : %4d (size : %5"PRIu64", pts : %12"PRIu64")\n",
- ++count, ns, buffer->pts);
- mediamuxer_write_sample(myMuxer, track_index_vid, vid_pkt);
+ media_buffer_flags_e flags;
+ media_packet_get_flags(vid_pkt, &flags);
+ media_packet_set_flags(vid_pkt, flags | MEDIA_PACKET_CODEC_CONFIG);
}
+ gst_caps_unref(vid_caps);
}
+
+ /* Print count and size to indicate a received buffer */
+ g_print("Received video buffer count : %4d (size : %5"PRIu64", pts : %12"PRIu64")\n",
+ ++count, ns, buffer->pts);
+ mediamuxer_write_sample(myMuxer, track_index_vid, vid_pkt);
+
ERROR3:
media_packet_destroy(vid_pkt);
ERROR2:
g_signal_emit_by_name(sink, "pull-sample", &sample);
buffer = gst_sample_get_buffer(sample);
- if (buffer) {
- if (gst_buffer_map(buffer, &map, GST_MAP_READ)) {
- if (media_format_create(&textfmt)) {
- g_print("media_format_create(&textfmt) failed\n");
- gst_buffer_unmap(buffer, &map);
- return;
- }
+ if (!buffer) {
+ g_print("__text_app_sink_callback buffer is NULL");
+ return;
+ }
- if (media_format_set_text_mime(textfmt, MEDIA_FORMAT_TEXT_MP4)) {
- g_print("media_format_set_text_mime failed\n");
- goto ERROR1;
- }
+ if (!gst_buffer_map(buffer, &map, GST_MAP_READ)) {
+ g_print("__text_app_sink_callback buffer map is fail");
+ return;
+ }
- if (!GST_BUFFER_FLAG_IS_SET(buffer, GST_BUFFER_FLAG_DELTA_UNIT)) {
- /* Key Frame */
- key = 1;
- } else {
- /* Not a Key Frame */
- key = 0;
- }
+ if (media_format_create(&textfmt)) {
+ g_print("media_format_create(&textfmt) failed\n");
+ gst_buffer_unmap(buffer, &map);
+ return;
+ }
- if (media_packet_create(textfmt, NULL, NULL, &text_pkt)) {
- g_print("create text media_packet failed\n");
- goto ERROR1;
- }
+ if (media_format_set_text_mime(textfmt, MEDIA_FORMAT_TEXT_MP4)) {
+ g_print("media_format_set_text_mime failed\n");
+ goto ERROR1;
+ }
- if (media_packet_alloc(text_pkt)) {
- g_print("text media_packet_alloc failed\n");
- goto ERROR2;
- }
+ if (!GST_BUFFER_FLAG_IS_SET(buffer, GST_BUFFER_FLAG_DELTA_UNIT)) {
+ /* Key Frame */
+ key = 1;
+ } else {
+ /* Not a Key Frame */
+ key = 0;
+ }
- media_packet_get_buffer_data_ptr(text_pkt, (void**)&dptr);
- memcpy((char*)dptr, map.data, map.size);
+ if (media_packet_create(textfmt, NULL, NULL, &text_pkt)) {
+ g_print("create text media_packet failed\n");
+ goto ERROR1;
+ }
- if (media_packet_set_buffer_size(text_pkt, (uint64_t)(map.size))) {
- g_print("text set_buffer_size failed\n");
- goto ERROR2;
- }
+ if (media_packet_alloc(text_pkt)) {
+ g_print("text media_packet_alloc failed\n");
+ goto ERROR2;
+ }
- if (media_packet_get_buffer_size(text_pkt, &ns)) {
- g_print("unable to get the buffer size actual");
- goto ERROR2;
- }
+ media_packet_get_buffer_data_ptr(text_pkt, (void**)&dptr);
+ memcpy((char*)dptr, map.data, map.size);
- if (media_packet_set_codec_data(text_pkt, sub_caps, strlen(sub_caps)+1)) {
- g_print("unable to set the text codec data e\n");
- goto ERROR2;
- }
+ if (media_packet_set_buffer_size(text_pkt, (uint64_t)(map.size))) {
+ g_print("text set_buffer_size failed\n");
+ goto ERROR2;
+ }
- if (media_packet_set_pts(text_pkt, buffer->pts)) {
- g_print("unable to set the pts\n");
- goto ERROR2;
- }
+ if (media_packet_get_buffer_size(text_pkt, &ns)) {
+ g_print("unable to get the buffer size actual");
+ goto ERROR2;
+ }
- if (media_packet_set_dts(text_pkt, buffer->dts)) {
- g_print("unable to set the dts\n");
- goto ERROR2;
- }
+ if (media_packet_set_codec_data(text_pkt, sub_caps, strlen(sub_caps)+1)) {
+ g_print("unable to set the text codec data e\n");
+ goto ERROR2;
+ }
- if (media_packet_set_duration(text_pkt, buffer->duration)) {
- g_print("unable to set the duration\n");
- goto ERROR2;
- }
+ if (media_packet_set_pts(text_pkt, buffer->pts)) {
+ g_print("unable to set the pts\n");
+ goto ERROR2;
+ }
- if (media_packet_set_flags(text_pkt, key)) {
- g_print("unable to set the flag size\n");
- goto ERROR2;
- }
+ if (media_packet_set_dts(text_pkt, buffer->dts)) {
+ g_print("unable to set the dts\n");
+ goto ERROR2;
+ }
- /* Print count and size to indicate a received buffer */
- g_print("Received text buffer count : %4d (size : %5"PRIu64", pts : %12"PRIu64")\n",
- ++count, ns, buffer->pts);
+ if (media_packet_set_duration(text_pkt, buffer->duration)) {
+ g_print("unable to set the duration\n");
+ goto ERROR2;
+ }
- mediamuxer_write_sample(myMuxer, track_index_text, text_pkt);
- }
+ if (media_packet_set_flags(text_pkt, key)) {
+ g_print("unable to set the flag size\n");
+ goto ERROR2;
}
+ /* Print count and size to indicate a received buffer */
+ g_print("Received text buffer count : %4d (size : %5"PRIu64", pts : %12"PRIu64")\n",
+ ++count, ns, buffer->pts);
+
+ mediamuxer_write_sample(myMuxer, track_index_text, text_pkt);
+
ERROR2:
media_packet_destroy(text_pkt);
ERROR1: