#define GST_SECOND (G_USEC_PER_SEC * G_GINT64_CONSTANT(1000))
#endif
+#define DUMP_OUTBUF 0
#define USE_INPUT_QUEUE 1
#define MAX_INPUT_BUF_NUM 20
#define CHECK_BIT(x, y) (((x) >> (y)) & 0x01)
static int samplebyte = DEFAULT_SAMPLEBYTE;
int enc_vide_pkt_available = 0;
FILE *fp_src = NULL;
-
+#if DUMP_OUTBUF
+FILE *fp_in = NULL;
+bool validate_dump = false;
+#endif
/* ----------------------------------------------------------------------
| HELPER FUNCTION |
---------------------------------------------------------------------- */
/* fill in ADTS data */
buffer[0] = (char)0xFF;
buffer[1] = (char)0xF1;
- buffer[2] = (char)(((profile-1)<<6) + (freqIdx<<2) +(chanCfg>>2));
- buffer[3] = (char)(((chanCfg&3)<<6) + (packetLen>>11));
- buffer[4] = (char)((packetLen&0x7FF) >> 3);
- buffer[5] = (char)(((packetLen&7)<<5) + 0x1F);
+ buffer[2] = (char)(((profile - 1) << 6) + (freqIdx << 2) + (chanCfg >> 2));
+ buffer[3] = (char)(((chanCfg & 3) << 6) + (packetLen >> 11));
+ buffer[4] = (char)((packetLen & 0x7FF) >> 3);
+ buffer[5] = (char)(((packetLen & 7) << 5) + 0x1F);
buffer[6] = (char)0xFC;
}
/* To aid muxer-codec test */
-static void _mediacodec_fill_buffer_cb(media_packet_h pkt, void *user_data)
+static void _mediacodec_fill_buffer_cb(media_packet_h out_pkt, void *user_data)
{
g_print("**** Entered _mediacodec_fill_buffer_cb *****\n");
int track_index_aud = 1;
uint64_t pts, dts, duration, size;
media_buffer_flags_e flags;
void *codec_data;
+ bool is_eos = false;
+#if DUMP_OUTBUF
void *pkt_data;
+#endif
unsigned int codec_data_size;
+ media_packet_h pkt = NULL;
+ mediacodec_h codec_handle = (mediacodec_h)user_data;
+
+ if (!user_data)
+ return;
+
+ mediacodec_get_output(codec_handle, &pkt, 0);
+ if (!pkt) {
+ g_print("media codec output buffer is NULL\n");
+ return;
+ }
g_print("A%d write sample call. packet add:%p\n", ++count, pkt);
if (media_packet_get_buffer_size(pkt, &size)) {
g_print("unable to get the buffer size actual =%"PRIu64"\n", size);
+ media_packet_destroy(pkt);
return;
}
-
+ /* for print log */
media_packet_get_pts(pkt, &pts);
media_packet_get_dts(pkt, &dts);
media_packet_get_duration(pkt, &duration);
/* offset */
media_packet_get_flags(pkt, &flags);
- media_packet_get_extra(pkt, (void**)&codec_data);
- codec_data_size = strlen(codec_data) + 1;
+ media_packet_get_codec_data(pkt, (void **)&codec_data, &codec_data_size);
g_print("***pkt attributes before writing *** Size=%"PRIu64", pts=%"PRIu64", dts=%"PRIu64", duration=%"PRIu64", flags=%d\n", size, pts, dts, duration, (int)flags);
- g_print("Codec_data=%s\ncodec_data_size = %d\n", (char*)codec_data, codec_data_size);
+ g_print("Codec_data=%s\ncodec_data_size = %d\n", (char *)codec_data, codec_data_size);
#if DUMP_OUTBUF
if (count == 0) {
- fp_in = fopen("/opt/usr/codec_dump_mxr.aac", "wb");
+ fp_in = fopen("/tmp/codec_dump_mxr.aac", "wb");
if (fp_in != NULL)
validate_dump = true;
else
}
#endif
- /* EOS hack for mediacodec */
- if (count == 1758) { /* Last buffer for SampleAAC.aac. should be replaced with a valid eos. */
- g_print("Last Buffer Reached\n");
#if DUMP_OUTBUF
- fclose(fp_in);
-#endif
- _mediacodec_eos_cb(user_data);
- goto Finalize;
- }
-
media_packet_get_buffer_data_ptr(pkt, &pkt_data);
-#if DUMP_OUTBUF
if (validate_dump)
fwrite(pkt_data, 1, size, fp_in);
#endif
mediamuxer_write_sample(myMuxer, track_index_aud, pkt);
-Finalize:
+ /* EOS hack for mediacodec */
+ media_packet_is_end_of_stream(pkt, &is_eos);
+ if (is_eos) {
+ g_print("Last Buffer Reached\n");
+#if DUMP_OUTBUF
+ fclose(fp_in);
+#endif
+ }
+
+ media_packet_destroy(pkt);
return;
}
{
if (pkt != NULL) {
#if USE_INPUT_QUEUE
- media_packet_unset_flags(pkt, MEDIA_PACKET_CODEC_CONFIG);
- g_queue_push_tail(&input_available, pkt);
- g_print("availablebuf = %p\n", pkt);
+ media_packet_unset_flags(pkt, MEDIA_PACKET_CODEC_CONFIG);
+ g_queue_push_tail(&input_available, pkt);
+ g_print("availablebuf = %p\n", pkt);
#else
- g_print("Used input buffer = %p\n", pkt);
- media_packet_destroy(pkt);
+ g_print("Used input buffer = %p\n", pkt);
+ media_packet_destroy(pkt);
#endif
}
return;
if (feof(fd))
return 0;
- read_size = width*height*3/2;
+ read_size = width * height * 3 / 2;
result = fread(buffer, 1, read_size, fd);
- g_print("3\n");
if (result != read_size)
return -1;
- memcpy(yuv, buffer, width*height*3/2);
+ memcpy(yuv, buffer, read_size);
- return width*height*3/2;
+ return read_size;
}
/* To aid muxer-codec test */
if (feof(fd))
return 0;
- readsize = ((samplebyte*channel)*(bit/8));
+ readsize = ((samplebyte * channel) * (bit / 8));
result = fread(buffer, 1, readsize, fd);
if (result != readsize)
- return -1;
+ g_print("different size of read. result is %d\n", result);
- memcpy(rawdata, buffer, readsize);
+ memcpy(rawdata, buffer, result);
- return readsize;
+ return result;
}
/* To aid muxer-codec test */
if (fp_src == NULL) {
if (bMultipleFiles) {
- if (g_uri[g_len-1] != '/')
+ if (g_uri[g_len - 1] != '/')
g_uri[g_len++] = '/';
- snprintf(g_uri+g_len, MAX_STRING_LEN - g_len, "%05d", frame_count);
+ snprintf(g_uri + g_len, MAX_STRING_LEN - g_len, "%05d", frame_count);
}
fp_src = fopen(g_uri, "r");
if (fp_src == NULL) {
if (bMultipleFiles) {
buf_size = __extract_input_per_frame(fp_src, data);
fclose(fp_src);
- snprintf(g_uri+g_len, MAX_STRING_LEN-g_len, "%05d", frame_count+1);
+ snprintf(g_uri + g_len, MAX_STRING_LEN - g_len, "%05d", frame_count + 1);
fp_src = fopen(g_uri, "r");
if (fp_src == NULL) {
media_packet_set_flags(in_buf, MEDIA_PACKET_END_OF_STREAM);
buf_size = __extract_input_aacenc(fp_src, data);
g_print("audio buf_size=%d\n", buf_size);
/* pts is not needed for muxer, if adts header is present */
- /* media_packet_set_pts (in_buf, pts); */
g_print("----pts calculation: input pts = %"PRIu64", buf_size=%d samplerate=%d, samplebyte=%d\n", pts, buf_size, samplerate, samplebyte);
+ media_packet_set_pts(in_buf, pts);
if (samplerate != 0)
pts += ((GST_SECOND / samplerate) * samplebyte);
}
}
- if (buf_size >= 0) {
+ if (buf_size > 0) {
if (use_video && buf_size == 4) {
media_packet_set_flags(in_buf, MEDIA_PACKET_END_OF_STREAM);
media_packet_set_buffer_size(in_buf, 4);
g_print("%s - input_buf size = %4d (0x%x) at %4d frame, %p\n", __func__, buf_size, buf_size, frame_count, in_buf);
ret = mediacodec_process_input(g_media_codec[0], in_buf, 0);
+ } else if (buf_size == 0) {
+ media_packet_set_flags(in_buf, MEDIA_PACKET_END_OF_STREAM);
+ media_packet_set_buffer_size(in_buf, 0);
+ mediacodec_process_input(g_media_codec[0], in_buf, 0);
+ g_print("\n\nEOS packet is sent\n");
+ return MEDIACODEC_ERROR_INVALID_INBUFFER;
} else {
g_print("%s - [WARN] Check to input buf_size = %4d at %4d frame, %p\n", __func__, buf_size, frame_count, in_buf);
return MEDIACODEC_ERROR_INVALID_INBUFFER;