#include <mediademuxer.h>
#include <media_format.h>
#include <media_packet.h>
+#ifdef USE_MEDIA_CODEC
#include <media_codec.h>
+#endif
/*-----------------------------------------------------------------------
| GLOBAL CONSTANT DEFINITIONS: |
#endif
bool validate_with_codec = false;
-mediacodec_h g_media_codec = NULL;
+
FILE *fp_out_codec_audio = NULL;
-mediacodec_h g_media_codec_1 = NULL;
FILE *fp_out_codec_video = NULL;
+#ifdef USE_MEDIA_CODEC
+mediacodec_h g_media_codec = NULL;
+mediacodec_h g_media_codec_1 = NULL;
+#endif
/*-----------------------------------------------------------------------
| HELPER FUNCTION |
return ret;
}
+#ifdef USE_MEDIA_CODEC
static void mediacodec_finish(mediacodec_h handle, FILE *fp)
{
int err = 0;
}
}
+static void _mediacodec_fill_video_buffer_cb(media_packet_h pkt, void *user_data)
+{
+ int err = 0;
+ uint64_t buf_size = 0;
+ void *data = NULL;
+ media_packet_h output_buf;
+
+ if (pkt != NULL) {
+ err = mediacodec_get_output(g_media_codec_1, &output_buf, 0);
+ if (err == MEDIACODEC_ERROR_NONE) {
+ media_packet_get_buffer_size(output_buf, &buf_size);
+ /* g_print("%s - output_buf size = %lld\n", __func__, buf_size); */
+ media_packet_get_buffer_data_ptr(output_buf, &data);
+ if (data != NULL)
+ fwrite(data, 1, buf_size, fp_out_codec_video);
+ else
+ g_print("Data is null inside _mediacodec_fill_video_buffer_cb\n");
+ media_packet_destroy(output_buf);
+ } else {
+ g_print("mediacodec_get_output failed inside _mediacodec_fill_video_buffer_cb lerr = %d\n", err);
+ return;
+ }
+ } else {
+ g_print("video pkt from mediacodec is null\n");
+ }
+ return;
+}
+
+static void mediacodec_init_video(int codecid, int flag, int width, int height)
+{
+ /* This file will be used to dump the data */
+ fp_out_codec_video = fopen("/opt/usr/codec_dump_video.out", "wb");
+ g_print("Create dumped file as codec_dump_video.out\n");
+
+ if (g_media_codec_1 != NULL) {
+ mediacodec_unprepare(g_media_codec_1);
+ mediacodec_destroy(g_media_codec_1);
+ g_media_codec_1 = NULL;
+ }
+ if (mediacodec_create(&g_media_codec_1) != MEDIACODEC_ERROR_NONE) {
+ g_print("mediacodec_create is failed\n");
+ return;
+ }
+ /* Now set the code info */
+ if ((mediacodec_set_codec(g_media_codec_1, (mediacodec_codec_type_e)codecid,
+ (mediacodec_support_type_e)flag) != MEDIACODEC_ERROR_NONE)) {
+ g_print("mediacodec_set_codec is failed\n");
+ return;
+ }
+ /* set the video dec info */
+ if ((mediacodec_set_vdec_info(g_media_codec_1, width, height)) != MEDIACODEC_ERROR_NONE) {
+ g_print("mediacodec_set_vdec is failed\n");
+ return;
+ }
+ /* Set the callback for output data, which will be used to write the data to file */
+ mediacodec_set_output_buffer_available_cb(g_media_codec_1,
+ _mediacodec_fill_video_buffer_cb,
+ g_media_codec_1);
+
+ if (MEDIACODEC_ERROR_NONE != mediacodec_prepare(g_media_codec_1)) {
+ g_print("mediacodec_prepare is failed\n");
+ return;
+ }
+}
+
+static void mediacodec_process_video_pkt(media_packet_h in_buf)
+{
+ if (g_media_codec_1 != NULL) {
+ /* process the media packet */
+ if (MEDIACODEC_ERROR_NONE != mediacodec_process_input(g_media_codec_1, in_buf, 0)) {
+ g_print("mediacodec process input is failed inside mediacodec_process_video_pkt\n");
+ return;
+ }
+ } else {
+ g_print("mediacodec handle is invalid inside mediacodec_process_video_pkt()\n");
+ }
+}
+
+#endif
+
void *_fetch_audio_data(void *ptr)
{
int ret = MEDIADEMUXER_ERROR_NONE;
*status = -1;
g_print("Audio Data function\n");
+#ifdef USE_MEDIA_CODEC
if (validate_with_codec) {
int flag = 0;
if (a_mime == MEDIA_FORMAT_AAC_LC || a_mime == MEDIA_FORMAT_AAC_HE ||
return (void *)status;
}
}
-
+#endif
while (1) {
ret = mediademuxer_read_sample(demuxer, aud_track, &audbuf);
if (ret != MEDIADEMUXER_ERROR_NONE) {
}
#endif
+#ifdef USE_MEDIA_CODEC
if (validate_with_codec)
mediacodec_process_audio_pkt(audbuf);
else
+#endif
media_packet_destroy(audbuf);
}
g_print("EOS return of mediademuxer_read_sample() for audio\n");
*status = 0;
+#ifdef USE_MEDIA_CODEC
if (validate_with_codec)
mediacodec_finish(g_media_codec, fp_out_codec_audio);
+#endif
return (void *)status;
}
-static void _mediacodec_fill_video_buffer_cb(media_packet_h pkt, void *user_data)
-{
- int err = 0;
- uint64_t buf_size = 0;
- void *data = NULL;
- media_packet_h output_buf;
-
- if (pkt != NULL) {
- err = mediacodec_get_output(g_media_codec_1, &output_buf, 0);
- if (err == MEDIACODEC_ERROR_NONE) {
- media_packet_get_buffer_size(output_buf, &buf_size);
- /* g_print("%s - output_buf size = %lld\n", __func__, buf_size); */
- media_packet_get_buffer_data_ptr(output_buf, &data);
- if (data != NULL)
- fwrite(data, 1, buf_size, fp_out_codec_video);
- else
- g_print("Data is null inside _mediacodec_fill_video_buffer_cb\n");
- media_packet_destroy(output_buf);
- } else {
- g_print("mediacodec_get_output failed inside _mediacodec_fill_video_buffer_cb lerr = %d\n", err);
- return;
- }
- } else {
- g_print("video pkt from mediacodec is null\n");
- }
- return;
-}
-
-static void mediacodec_init_video(int codecid, int flag, int width, int height)
-{
- /* This file will be used to dump the data */
- fp_out_codec_video = fopen("/opt/usr/codec_dump_video.out", "wb");
- g_print("Create dumped file as codec_dump_video.out\n");
-
- if (g_media_codec_1 != NULL) {
- mediacodec_unprepare(g_media_codec_1);
- mediacodec_destroy(g_media_codec_1);
- g_media_codec_1 = NULL;
- }
- if (mediacodec_create(&g_media_codec_1) != MEDIACODEC_ERROR_NONE) {
- g_print("mediacodec_create is failed\n");
- return;
- }
- /* Now set the code info */
- if ((mediacodec_set_codec(g_media_codec_1, (mediacodec_codec_type_e)codecid,
- (mediacodec_support_type_e)flag) != MEDIACODEC_ERROR_NONE)) {
- g_print("mediacodec_set_codec is failed\n");
- return;
- }
- /* set the video dec info */
- if ((mediacodec_set_vdec_info(g_media_codec_1, width, height)) != MEDIACODEC_ERROR_NONE) {
- g_print("mediacodec_set_vdec is failed\n");
- return;
- }
- /* Set the callback for output data, which will be used to write the data to file */
- mediacodec_set_output_buffer_available_cb(g_media_codec_1,
- _mediacodec_fill_video_buffer_cb,
- g_media_codec_1);
-
- if (MEDIACODEC_ERROR_NONE != mediacodec_prepare(g_media_codec_1)) {
- g_print("mediacodec_prepare is failed\n");
- return;
- }
-}
-
-static void mediacodec_process_video_pkt(media_packet_h in_buf)
-{
- if (g_media_codec_1 != NULL) {
- /* process the media packet */
- if (MEDIACODEC_ERROR_NONE != mediacodec_process_input(g_media_codec_1, in_buf, 0)) {
- g_print("mediacodec process input is failed inside mediacodec_process_video_pkt\n");
- return;
- }
- } else {
- g_print("mediacodec handle is invalid inside mediacodec_process_video_pkt()\n");
- }
-}
-
#if 0
static void _local_media_packet_get_codec_data(media_packet_h pkt)
{
*status = -1;
g_print("Video Data function\n");
+#ifdef USE_MEDIA_CODEC
if (validate_with_codec) {
int flag = 0;
if (v_mime == MEDIA_FORMAT_H264_SP || v_mime == MEDIA_FORMAT_H264_MP ||
return (void *)status;
}
}
+#endif
while (1) {
ret = mediademuxer_read_sample(demuxer, vid_track, &vidbuf);
if (ret != MEDIADEMUXER_ERROR_NONE) {
}
#endif
+#ifdef USE_MEDIA_CODEC
if (validate_with_codec)
mediacodec_process_video_pkt(vidbuf);
else
+#endif
media_packet_destroy(vidbuf);
}
g_print("EOS return of mediademuxer_read_sample() for video\n");
*status = 0;
+
+#ifdef USE_MEDIA_CODEC
if (validate_with_codec)
mediacodec_finish(g_media_codec_1, fp_out_codec_video);
-
+#endif
return (void *)status;
}
g_print("d. Destroy \t");
g_print("q. Quit \n");
g_print("---------------------------------------------------------------------------\n");
+#ifdef USE_MEDIA_CODEC
if (validate_with_codec)
g_print("[Validation with Media codec]\n");
else
+#endif
g_print("[validation as stand alone. To validate with media codec, run mediademuxertest with -c option]\n");
}
test_mediademuxer_is_encrypted();
else
g_print("UNKNOW COMMAND\n");
- } else if (len == 2) {
- if (strncmp(cmd, "10", len) == 0)
- g_print("UNKNOW COMMAND\n");
- else
- g_print("UNKNOW COMMAND\n");
} else {
g_print("UNKNOW COMMAND\n");
}