-
-/* START TAG HERE */
-gboolean _mmstreamrecorder_audio_add_metadata_info_m4a(MMHandleType handle)
-{
- FILE *f = NULL;
- guchar buf[4];
- guint64 udta_size = 0;
- gint64 current_pos = 0;
- gint64 moov_pos = 0;
- gint64 udta_pos = 0;
- char err_msg[128] = { '\0', };
-
- _MMStreamRecorderFileInfo *finfo = NULL;
- mmf_streamrecorder_t *hstreamrecorder = MMF_STREAMRECORDER(handle);
- _MMStreamRecorderSubContext *sc = NULL;
-
- mmf_return_val_if_fail(hstreamrecorder, MM_ERROR_STREAMRECORDER_NOT_INITIALIZED);
- sc = MMF_STREAMRECORDER_SUBCONTEXT(handle);
-
- mmf_return_val_if_fail(sc, MM_ERROR_STREAMRECORDER_NOT_INITIALIZED);
- mmf_return_val_if_fail(sc->info_file, MM_ERROR_STREAMRECORDER_NOT_INITIALIZED);
-
- finfo = sc->info_file;
-
- f = fopen(finfo->filename, "rb+");
- if (f == NULL) {
- strerror_r(errno, err_msg, 128);
- _mmstreamrec_dbg_err("file open failed [%s]", err_msg);
- return FALSE;
- }
-
- /* find udta container.
- if, there are udta container, write loci box after that
- else, make udta container and write loci box. */
- if (_mmstreamrecorder_find_fourcc(f, MMSTREAMRECORDER_FOURCC('u', 'd', 't', 'a'), TRUE)) {
- size_t nread = 0;
-
- _mmstreamrec_dbg_log("find udta container");
-
- /* read size */
- if (fseek(f, -8L, SEEK_CUR) != 0)
- goto fail;
-
- udta_pos = ftell(f);
- if (udta_pos < 0)
- goto ftell_fail;
-
- nread = fread(&buf, sizeof(char), sizeof(buf), f);
-
- _mmstreamrec_dbg_log("recorded file fread %d", nread);
-
- udta_size = _mmstreamrecorder_get_container_size(buf);
-
- /* goto end of udta and write 'smta' box */
- if (fseek(f, (udta_size - 4L), SEEK_CUR) != 0)
- goto fail;
-
- current_pos = ftell(f);
- if (current_pos < 0)
- goto ftell_fail;
-
- if (!_mmstreamrecorder_update_size(f, udta_pos, current_pos))
- goto fail;
- } else {
- _mmstreamrec_dbg_log("No udta container");
- if (fseek(f, 0, SEEK_END) != 0)
- goto fail;
-
- if (!_mmstreamrecorder_write_udta_m4a(f))
- goto fail;
- }
-
- /* find moov container.
- update moov container size. */
- if ((current_pos = ftell(f)) < 0)
- goto ftell_fail;
-
- if (_mmstreamrecorder_find_fourcc(f, MMSTREAMRECORDER_FOURCC('m', 'o', 'o', 'v'), TRUE)) {
-
- _mmstreamrec_dbg_log("found moov container");
- if (fseek(f, -8L, SEEK_CUR) != 0)
- goto fail;
-
- moov_pos = ftell(f);
- if (moov_pos < 0)
- goto ftell_fail;
-
- if (!_mmstreamrecorder_update_size(f, moov_pos, current_pos))
- goto fail;
-
- } else {
- _mmstreamrec_dbg_err("No 'moov' container");
- goto fail;
- }
-
- fclose(f);
- return TRUE;
-
- fail:
- fclose(f);
- return FALSE;
-
- ftell_fail:
- _mmstreamrec_dbg_err("ftell() returns negative value.");
- fclose(f);
- return FALSE;
-}
-
-/* END TAG HERE */