MetaDataUtils.cpp revision 7dc218e17800cc3ac95551e3280820f407adf7b5
1/* 2 * Copyright 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17//#define LOG_NDEBUG 0 18#define LOG_TAG "MetaDataUtils" 19 20#include <media/stagefright/foundation/avc_utils.h> 21#include <media/stagefright/foundation/ABuffer.h> 22#include <media/stagefright/MediaDefs.h> 23#include <media/stagefright/MetaDataUtils.h> 24 25namespace android { 26 27sp<MetaData> MakeAVCCodecSpecificData(const sp<ABuffer> &accessUnit) { 28 int32_t width; 29 int32_t height; 30 int32_t sarWidth; 31 int32_t sarHeight; 32 sp<ABuffer> csd = MakeAVCCodecSpecificData(accessUnit, &width, &height, &sarWidth, &sarHeight); 33 if (csd == nullptr) { 34 return nullptr; 35 } 36 sp<MetaData> meta = new MetaData; 37 meta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_AVC); 38 39 meta->setData(kKeyAVCC, kTypeAVCC, csd->data(), csd->size()); 40 meta->setInt32(kKeyWidth, width); 41 meta->setInt32(kKeyHeight, height); 42 if (sarWidth > 0 && sarHeight > 0) { 43 meta->setInt32(kKeySARWidth, sarWidth); 44 meta->setInt32(kKeySARHeight, sarHeight); 45 } 46 return meta; 47} 48 49sp<MetaData> MakeAACCodecSpecificData( 50 unsigned profile, unsigned sampling_freq_index, 51 unsigned channel_configuration) { 52 int32_t sampleRate; 53 int32_t channelCount; 54 sp<ABuffer> csd = MakeAACCodecSpecificData(profile, sampling_freq_index, 55 channel_configuration, &sampleRate, &channelCount); 56 if (csd == nullptr) { 57 return nullptr; 58 } 59 sp<MetaData> meta = new MetaData; 60 meta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_AUDIO_AAC); 61 62 meta->setInt32(kKeySampleRate, sampleRate); 63 meta->setInt32(kKeyChannelCount, channelCount); 64 65 meta->setData(kKeyESDS, 0, csd->data(), csd->size()); 66 return meta; 67} 68 69} // namespace android 70