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_mp4_stsz_size_free(metadata_info *meta_info) { 29 if (meta_info->ia_mp4_stsz_size != NULL) { 30 free(meta_info->ia_mp4_stsz_size); 31 meta_info->ia_mp4_stsz_size = NULL; 32 } 33 } 34 35 int ixheaacd_read_metadata_info(FILE *g_pf_metadata, metadata_info *meta_info) { 36 char cmd[IA_MAX_CMDLINE_LENGTH]; 37 38 WORD32 i, j, k, l; 39 i = j = k = l = 0; 40 metadata_mp4_stsz_size_free(meta_info); 41 while (fgets((char *)cmd, IA_MAX_CMDLINE_LENGTH, g_pf_metadata)) { 42 if (!strncmp((pCHAR8)cmd, "-dec_info_init:", 15)) { 43 pCHAR8 pb_arg_val = (pCHAR8)(cmd + 15); 44 UWORD32 dec_info_init = atoi(pb_arg_val); 45 meta_info->dec_info_init = dec_info_init; 46 } else if (!strncmp((pCHAR8)cmd, "-g_track_count:", 15)) { 47 pCHAR8 pb_arg_val = (pCHAR8)(cmd + 15); 48 UWORD32 g_track_count = atoi(pb_arg_val); 49 meta_info->g_track_count = g_track_count; 50 } 51 52 else if (!strncmp((pCHAR8)cmd, "-movie_time_scale:", 18)) { 53 pCHAR8 pb_arg_val = (pCHAR8)(cmd + 18); 54 UWORD32 movie_time_scale = atoi(pb_arg_val); 55 meta_info->movie_time_scale = movie_time_scale; 56 } 57 58 else if (!strncmp((pCHAR8)cmd, "-media_time_scale:", 18)) { 59 pCHAR8 pb_arg_val = (pCHAR8)(cmd + 18); 60 UWORD32 media_time_scale = atoi(pb_arg_val); 61 meta_info->media_time_scale = media_time_scale; 62 } 63 64 else if (!strncmp((pCHAR8)cmd, "-ia_mp4_stsz_entries:", 21)) { 65 pCHAR8 pb_arg_val = (pCHAR8)(cmd + 21); 66 UWORD32 ia_mp4_stsz_entries = atoi(pb_arg_val); 67 meta_info->ia_mp4_stsz_entries = ia_mp4_stsz_entries; 68 metadata_mp4_stsz_size_free(meta_info); 69 meta_info->ia_mp4_stsz_size = 70 (UWORD32 *)malloc(sizeof(UWORD32) * ia_mp4_stsz_entries); 71 memset(meta_info->ia_mp4_stsz_size, 0, 72 sizeof(UWORD32) * ia_mp4_stsz_entries); 73 } 74 /* 75 else if { 76 //printf("Wrong file order,Check file order"); 77 //return -1; 78 } 79 */ 80 else if (!strncmp((pCHAR8)cmd, "-playTimeInSamples:", 19)) { 81 pCHAR8 pb_arg_val = (pCHAR8)(cmd + 19); 82 UWORD32 playTimeInSamples = atoi(pb_arg_val); 83 meta_info->playTimeInSamples[i] = playTimeInSamples; 84 i++; 85 } 86 87 else if (!strncmp((pCHAR8)cmd, "-startOffsetInSamples:", 22)) { 88 pCHAR8 pb_arg_val = (pCHAR8)(cmd + 22); 89 UWORD32 startOffsetInSamples = atoi(pb_arg_val); 90 meta_info->startOffsetInSamples[j] = startOffsetInSamples; 91 j++; 92 } 93 94 else if (!strncmp((pCHAR8)cmd, "-useEditlist:", 13)) { 95 pCHAR8 pb_arg_val = (pCHAR8)(cmd + 13); 96 UWORD32 useEditlist = atoi(pb_arg_val); 97 meta_info->useEditlist[k] = useEditlist; 98 k++; 99 } 100 101 else if (!strncmp((pCHAR8)cmd, "-ia_mp4_stsz_size:", 18)) { 102 pCHAR8 pb_arg_val = (pCHAR8)(cmd + 18); 103 UWORD32 ia_mp4_stsz_size = atoi(pb_arg_val); 104 meta_info->ia_mp4_stsz_size[l] = ia_mp4_stsz_size; 105 l++; 106 } 107 108 else { 109 printf("Command not found"); 110 return -1; 111 } 112 } 113 114 for (; i < MAX_TRACKS_PER_LAYER; i++) { 115 meta_info->playTimeInSamples[i] = 0; 116 } 117 118 for (; j < MAX_TRACKS_PER_LAYER; j++) { 119 meta_info->startOffsetInSamples[j] = 0; 120 } 121 122 for (; k < MAX_TRACKS_PER_LAYER; k++) { 123 meta_info->useEditlist[k] = 0; 124 } 125 126 return 0; 127 } 128 129 int get_metadata_dec_info_init(metadata_info meta_info) { 130 return meta_info.dec_info_init; 131 } 132 133 WORD32 get_metadata_dec_exec(metadata_info meta_info, int frame) { 134 if (frame < (int)meta_info.ia_mp4_stsz_entries) { 135 return meta_info.ia_mp4_stsz_size[frame]; 136 } else { 137 return 0; 138 } 139 } 140 141 int get_movie_time_scale(metadata_info meta_info) { 142 return meta_info.movie_time_scale; 143 } 144 145 int get_media_time_scale(metadata_info meta_info) { 146 return meta_info.media_time_scale; 147 } 148 149 int get_g_track_count(metadata_info meta_info) { 150 return meta_info.g_track_count; 151 } 152 153 int get_use_edit_list(metadata_info meta_info) { 154 return meta_info.useEditlist[0]; 155 } 156 157 int get_start_offset_in_samples(metadata_info meta_info) { 158 return meta_info.startOffsetInSamples[0]; 159 } 160 161 int get_play_time_in_samples(metadata_info meta_info) { 162 return meta_info.playTimeInSamples[0]; 163 } 164 /* 165 void update_start_offset_in_samples(metadata_info meta_info, int update) 166 { 167 168 meta_info.startOffsetInSamples[0]=update; 169 } 170 */ 171 172 /* 173 void update_play_time_in_samples(metadata_info meta_info, int update) 174 { 175 176 meta_info.playTimeInSamples[0]=update; 177 178 } 179 */ 180