1 /****************************************************************************** 2 * * 3 * Copyright (C) 2018 The Android Open Source Project 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at: 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 ***************************************************************************** 18 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore 19 */ 20 #include "ixheaacd_type_def.h" 21 #include <stdlib.h> 22 #include <stdio.h> 23 #include <string.h> 24 #include "ixheaacd_metadata_read.h" 25 26 #define IA_MAX_CMDLINE_LENGTH 100 27 28 void metadata_info_init(metadata_info *meta_info) { 29 meta_info = (metadata_info *)malloc(sizeof(metadata_info)); 30 } 31 32 void metadata_free(metadata_info *meta_info) { 33 if (meta_info->ia_mp4_stsz_size != NULL) free(meta_info->ia_mp4_stsz_size); 34 // free(meta_info); 35 } 36 37 int ixheaacd_read_metadata_info(FILE *g_pf_metadata, metadata_info *meta_info) { 38 char cmd[IA_MAX_CMDLINE_LENGTH]; 39 40 WORD32 file_count = 0; 41 WORD32 i, j, k, l; 42 i = j = k = l = 0; 43 while (fgets((char *)cmd, IA_MAX_CMDLINE_LENGTH, g_pf_metadata)) { 44 if (!strncmp((pCHAR8)cmd, "-dec_info_init:", 15)) { 45 pCHAR8 pb_arg_val = (pCHAR8)(cmd + 15); 46 UWORD32 dec_info_init = atoi(pb_arg_val); 47 meta_info->dec_info_init = dec_info_init; 48 file_count++; 49 } 50 else if (!strncmp((pCHAR8)cmd, "-g_track_count:", 15)) { 51 pCHAR8 pb_arg_val = (pCHAR8)(cmd + 15); 52 UWORD32 g_track_count = atoi(pb_arg_val); 53 meta_info->g_track_count = g_track_count; 54 file_count++; 55 } 56 57 else if (!strncmp((pCHAR8)cmd, "-movie_time_scale:", 18)) { 58 pCHAR8 pb_arg_val = (pCHAR8)(cmd + 18); 59 UWORD32 movie_time_scale = atoi(pb_arg_val); 60 meta_info->movie_time_scale = movie_time_scale; 61 file_count++; 62 } 63 64 else if (!strncmp((pCHAR8)cmd, "-media_time_scale:", 18)) { 65 pCHAR8 pb_arg_val = (pCHAR8)(cmd + 18); 66 UWORD32 media_time_scale = atoi(pb_arg_val); 67 meta_info->media_time_scale = media_time_scale; 68 file_count++; 69 } 70 71 else if (!strncmp((pCHAR8)cmd, "-ia_mp4_stsz_entries:", 21)) { 72 pCHAR8 pb_arg_val = (pCHAR8)(cmd + 21); 73 UWORD32 ia_mp4_stsz_entries = atoi(pb_arg_val); 74 meta_info->ia_mp4_stsz_entries = ia_mp4_stsz_entries; 75 76 meta_info->ia_mp4_stsz_size = 77 (UWORD32 *)malloc(sizeof(int) * ia_mp4_stsz_entries); 78 file_count++; 79 } 80 /* 81 else if { 82 //printf("Wrong file order,Check file order"); 83 //return -1; 84 } 85 */ 86 else if (!strncmp((pCHAR8)cmd, "-playTimeInSamples:", 19)) { 87 pCHAR8 pb_arg_val = (pCHAR8)(cmd + 19); 88 UWORD32 playTimeInSamples = atoi(pb_arg_val); 89 meta_info->playTimeInSamples[i] = playTimeInSamples; 90 i++; 91 } 92 93 else if (!strncmp((pCHAR8)cmd, "-startOffsetInSamples:", 22)) { 94 pCHAR8 pb_arg_val = (pCHAR8)(cmd + 22); 95 UWORD32 startOffsetInSamples = atoi(pb_arg_val); 96 meta_info->startOffsetInSamples[j] = startOffsetInSamples; 97 j++; 98 } 99 100 else if (!strncmp((pCHAR8)cmd, "-useEditlist:", 13)) { 101 pCHAR8 pb_arg_val = (pCHAR8)(cmd + 13); 102 UWORD32 useEditlist = atoi(pb_arg_val); 103 meta_info->useEditlist[k] = useEditlist; 104 k++; 105 } 106 107 else if (!strncmp((pCHAR8)cmd, "-ia_mp4_stsz_size:", 18)) { 108 pCHAR8 pb_arg_val = (pCHAR8)(cmd + 18); 109 UWORD32 ia_mp4_stsz_size = atoi(pb_arg_val); 110 meta_info->ia_mp4_stsz_size[l] = ia_mp4_stsz_size; 111 l++; 112 } 113 114 else { 115 printf("Command not found"); 116 return -1; 117 } 118 } 119 120 for (; i < MAX_TRACKS_PER_LAYER; i++) { 121 meta_info->playTimeInSamples[i] = 0; 122 } 123 124 for (; j < MAX_TRACKS_PER_LAYER; j++) { 125 meta_info->startOffsetInSamples[j] = 0; 126 } 127 128 for (; k < MAX_TRACKS_PER_LAYER; k++) { 129 meta_info->useEditlist[k] = 0; 130 } 131 132 return 0; 133 } 134 135 int get_metadata_dec_info_init(metadata_info meta_info) { 136 return meta_info.dec_info_init; 137 } 138 139 WORD32 get_metadata_dec_exec(metadata_info meta_info, int frame) { 140 return meta_info.ia_mp4_stsz_size[frame]; 141 } 142 143 int get_movie_time_scale(metadata_info meta_info) { 144 return meta_info.movie_time_scale; 145 } 146 147 int get_media_time_scale(metadata_info meta_info) { 148 return meta_info.media_time_scale; 149 } 150 151 int get_g_track_count(metadata_info meta_info) { 152 return meta_info.g_track_count; 153 } 154 155 int get_use_edit_list(metadata_info meta_info) { 156 return meta_info.useEditlist[0]; 157 } 158 159 int get_start_offset_in_samples(metadata_info meta_info) { 160 return meta_info.startOffsetInSamples[0]; 161 } 162 163 int get_play_time_in_samples(metadata_info meta_info) { 164 return meta_info.playTimeInSamples[0]; 165 } 166 /* 167 void update_start_offset_in_samples(metadata_info meta_info, int update) 168 { 169 170 meta_info.startOffsetInSamples[0]=update; 171 } 172 */ 173 174 /* 175 void update_play_time_in_samples(metadata_info meta_info, int update) 176 { 177 178 meta_info.playTimeInSamples[0]=update; 179 180 } 181 */ 182 183 void memset_metadata(metadata_info meta_info) { 184 unsigned int i; 185 186 for (i = 0; i < meta_info.g_track_count; i++) { 187 meta_info.startOffsetInSamples[i] = 0; 188 meta_info.startOffsetInSamples[i] = 0; 189 meta_info.playTimeInSamples[i] = 0; 190 } 191 192 meta_info.g_track_count = 0; 193 } 194