}
static int _gst_copy_buf_to_media_packet(media_packet_h out_pkt,
- GstBuffer *buffer, char *codec_data)
+ GstBuffer *buffer, GstBuffer *codec_data)
{
MEDIADEMUXER_FENTER();
int ret = MD_ERROR_NONE;
ret = MD_ERROR_UNKNOWN;
goto ERROR;
}
+ /* set codec data into media packet */
if (codec_data) {
- if (media_packet_set_codec_data(out_pkt, (void*) codec_data, strlen(codec_data))) {
+ GstMapInfo codec_data_map;
+ if (!gst_buffer_map(codec_data, &codec_data_map, GST_MAP_READ)) {
+ MD_E("codec data buffer map failed\n");
+ ret = MD_ERROR_UNKNOWN;
+ goto ERROR;
+ }
+ if (media_packet_set_codec_data(out_pkt, (void*)codec_data_map.data,
+ (unsigned int)codec_data_map.size)) {
MD_E("unable to set the codec data\n");
ret = MD_ERROR_UNKNOWN;
+ gst_buffer_unmap(codec_data, &codec_data_map);
goto ERROR;
}
+ gst_buffer_unmap(codec_data, &codec_data_map);
}
ERROR:
gst_buffer_unmap(buffer, &map);
media_packet_h mediabuf = NULL;
int indx = 0;
- char *codec_data = NULL;
- char *temp_codec_data = NULL;
- int index = 0;
track *atrack = demuxer->info.head;
if ((demuxer->selected_tracks)[track_indx] == false) {
}
/* Create the codec data and pass to _gst_copy_buf_to_media_packet() to add into the media packet */
- temp_codec_data = strstr(atrack->caps_string, "codec_data");
- if (temp_codec_data != NULL) {
- while (*temp_codec_data != ')')
- temp_codec_data++;
- temp_codec_data++; /* to esacpe ')' */
- codec_data = (char*) malloc(sizeof(char)*strlen(temp_codec_data));
- if (codec_data != NULL) {
- while (*temp_codec_data != ',') {
- codec_data[index++] = *temp_codec_data;
- temp_codec_data++;
- }
- codec_data[index] = '\0';
- }
- }
+ GstStructure *structure = NULL;
+ const GValue *value = NULL;
+ GstBuffer *codec_data_buffer = NULL;
+ structure = gst_caps_get_structure(atrack->caps, 0);
+ value = gst_structure_get_value(structure, "codec_data");
+ if (value)
+ codec_data_buffer = gst_value_get_buffer(value);
/* Fill the media_packet with proper information */
- ret = _gst_copy_buf_to_media_packet(mediabuf, buffer, codec_data);
+ ret = _gst_copy_buf_to_media_packet(mediabuf, buffer, codec_data_buffer);
gst_sample_unref(sample);
*outbuf = mediabuf;
- if (codec_data)
- free(codec_data);
MEDIADEMUXER_FLEAVE();
return ret;