Added null check to output_uri in gst_add_track to return if set_data_sink fails.
Modify mediamuxer to return an error if the media_format during add_track is not matching with media_format of the write_sample packet
Update mediamuxer test-suite to return an error if inappropriate A/V codecs were fed.
Hence, user is restricted to feed a container-file with same encoded-media as what he choose during 'o'
Addressed review comments
Change-Id: Id8f4fe3637564e9957084f77dab5f6d856b4b2f6
Signed-off-by: Mahesh Kondiparthi <kd.mahesh@samsung.com>
mx_gst_track *current = NULL;
mx_gst_track *last = NULL;
+ if (!mx_handle_gst->output_uri) {
+ MX_E("URI is null. Possibly, set_data_sink failed. returning. \n");
+ return MX_ERROR_INVALID_ARGUMENT;
+ }
+
current = (mx_gst_track *)g_malloc(sizeof(mx_gst_track));
if (!current) {
MX_E("Not able to allocate memory\n");
current->parser = gst_element_factory_make("mpeg4videoparse", str_parser);
} else {
MX_E("Can't retrive mimetype for the current track. Unsupported MIME Type\n");
+ ret = MEDIAMUXER_ERROR_INVALID_PARAMETER;
+ goto ERROR;
}
if ((!current->appsrc) || (!current->parser)) {
char *codec_data;
unsigned int codec_data_size;
mx_gst_track *current = NULL;
+ media_format_mimetype_e track_mime;
+ media_format_mimetype_e current_mime;
/* Reach that track index and set the codec data */
for (current = gst_handle->track_info.track_head; current; current = current->next)
MX_E("\n\nThis is not an audio track_index. Track_index is not in 3*n+1 format\n\n");
goto ERROR;
}
+
+ /* return if track_mime is different to current_mime */
+ if (media_format_get_audio_info((media_format_h)(current->media_format), &track_mime, NULL, NULL, NULL, NULL)
+ == MEDIA_FORMAT_ERROR_NONE) {
+ if (media_format_get_audio_info((media_format_h)(format), ¤t_mime, NULL, NULL, NULL, NULL)
+ == MEDIA_FORMAT_ERROR_NONE) {
+ if (track_mime != current_mime) {
+ MX_E("audio track_mime is not matching with packet mime. returning");
+ return MX_ERROR_INVALID_ARGUMENT;
+ }
+ } else {
+ MX_E("cant read audio mime in packet. returning\n");
+ return MX_ERROR_INVALID_ARGUMENT;
+ }
+ } else {
+ MX_E("cant read audio mime, set during add_track. returning\n");
+ return MX_ERROR_INVALID_ARGUMENT;
+ }
+
if (media_packet_get_extra(packet,
(void **)&codec_data)) {
MX_E("media_packet_get_extra call failed\n");
MX_E("\n\nThis is not an video track_index. Video track_index is not in 3*n format\n\n");
goto ERROR;
}
+
+ /* return if track_mime is different to current_mime */
+ if (media_format_get_video_info((media_format_h)(current->media_format), &track_mime, NULL, NULL, NULL, NULL)
+ == MEDIA_FORMAT_ERROR_NONE) {
+ if (media_format_get_audio_info((media_format_h)(format), ¤t_mime, NULL, NULL, NULL, NULL)
+ == MEDIA_FORMAT_ERROR_NONE) {
+ if (track_mime != current_mime) {
+ MX_E("video track_mime is not matching with packet mime. returning");
+ return MX_ERROR_INVALID_ARGUMENT;
+ }
+ } else {
+ MX_E("cant read video mime. returning\n");
+ return MX_ERROR_INVALID_ARGUMENT;
+ }
+ } else {
+ MX_E("cant read video mime in packet. returning\n");
+ return MX_ERROR_INVALID_ARGUMENT;
+ }
+
if (media_packet_get_extra(packet,
(void **)&codec_data)) {
MX_E("media_packet_get_extra call failed\n");
goto ERROR;
}
- _gst_set_caps(pHandle, inbuf, track_index);
+ if (_gst_set_caps(pHandle, inbuf, track_index) != MX_ERROR_NONE) {
+ ret = MX_ERROR_INVALID_ARGUMENT;
+ goto ERROR;
+ }
+
MX_I("Track_index passed = %d, working-with_track_index = %d\n", track_index, current->track_index);
GstBuffer *gst_inbuf2 = NULL;
} else if (strncmp(data_sink, "42", 2) == 0) {
op_uri = "MuxTest_wb.amr";
ret = mediamuxer_set_data_sink(myMuxer, op_uri, MEDIAMUXER_CONTAINER_FORMAT_AMR_WB);
+ } else {
+ g_print("Invalid option choosen. Only the displayed options are valid\n");
+ ret = MEDIAMUXER_ERROR_INVALID_PARAMETER;
}
g_print("\nFile will be saved to: %s\n", op_uri);
test_mediamuxer_add_track_audio();
} else if (strncmp(cmd, "v", 1) == 0) {
if (!validate_with_codec) {
- have_vid_track = true;
- if (have_mp4 == false) {
- g_menu_state = CURRENT_STATUS_MP4_FILENAME;
- have_mp4 = true;
+ if ((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)) {
+ have_vid_track = true;
+ if (have_mp4 == false) {
+ g_menu_state = CURRENT_STATUS_MP4_FILENAME;
+ have_mp4 = true;
+ }
}
}
- test_mediamuxer_add_track_video();
+ if ((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))
+ test_mediamuxer_add_track_video();
+ else
+ g_print("Ignoring, data_sink=%s doesnt need video track testing", data_sink);
} else if (strncmp(cmd, "m", 1) == 0) {
test_mediamuxer_write_sample();
} else if (strncmp(cmd, "t", 1) == 0) {
return;
}
- if (g_str_has_prefix(new_pad_type_aud, "audio/mpeg")) {
+ 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");
return;
}
- } else if (g_str_has_prefix(new_pad_type_aud, "audio/AMR-WB")) {
+ } 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");
return;
}
- } else if (g_str_has_prefix(new_pad_type_aud, "audio/AMR")) {
+ } else if (g_str_has_prefix(new_pad_type_aud, "audio/AMR")
+ && (strncmp(data_sink, "23", 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");
return;
}
- } else if (g_str_has_prefix(new_pad_type_aud, "audio/x-wav")) { g_print("creating audio-wav\n");
+ } 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");
return;
g_print("wav media_format_set_audio_channel failed");
if (media_format_set_audio_samplerate(audfmt, 44100))
g_print("wav media_format_set_audio_samplerate failed");
- }
+ } else
+ g_print("Unsupported audio mime\n");
if (media_packet_create(audfmt, NULL, NULL, &aud_pkt)) {
g_print("create audio media_packet failed\n");
g_print("media_format_create failed\n");
return;
}
+ g_print("video data_sink = %s\n", data_sink);
- if (g_str_has_prefix(new_pad_type_vid, "video/x-h264")) {
+ /* 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 )) {
if (media_format_set_video_mime(vidfmt, MEDIA_FORMAT_H264_SP)) {
g_print("media_format_set_video_mime to H264_SP failed\n");
return;
}
- } else if (g_str_has_prefix(new_pad_type_vid, "video/mpeg")) {
+ } 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");
return;
}
- } else if (g_str_has_prefix(new_pad_type_vid, "video/x-h263")) {
+ } 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, "23", 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");
return;
}
- } else {
- g_print("Unsupported encoded video mime. Currently muxer supports:h263, h264 & mpeg4");
- }
+ } 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"); */