blob: 0c65e9e55246ceea2ddd8fc753b4753edaf57cb9 [file] [log] [blame]
Marco Nelissen0c3be872014-05-01 10:14:44 -07001/*
2 * Copyright (C) 2014 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
Marco Nelissenc7a11b22014-05-30 10:13:25 -070017//#define LOG_NDEBUG 0
Marco Nelissen0c3be872014-05-01 10:14:44 -070018#define LOG_TAG "NdkMediaExtractor"
19
20
Colin Cross7e8d4ba2017-05-04 16:17:42 -070021#include <media/NdkMediaError.h>
22#include <media/NdkMediaExtractor.h>
Marco Nelissen5dcf85a2018-10-11 09:49:02 -070023#include <media/NdkMediaErrorPriv.h>
Marco Nelissen98603d82018-07-17 11:06:55 -070024#include <media/NdkMediaFormatPriv.h>
Santiago Seifert1349f472020-11-11 23:49:28 +000025#include "NdkJavaVMHelperPriv.h"
Robert Shih0df451b2017-12-08 14:16:50 -080026#include "NdkMediaDataSourcePriv.h"
Marco Nelissen0c3be872014-05-01 10:14:44 -070027
28
Aurimas Liutikas214c8332016-02-19 14:48:23 -080029#include <inttypes.h>
Marco Nelissen0c3be872014-05-01 10:14:44 -070030#include <utils/Log.h>
31#include <utils/StrongPointer.h>
Marco Nelissen050eb322014-05-09 15:10:23 -070032#include <media/hardware/CryptoAPI.h>
Marco Nelissen0c3be872014-05-01 10:14:44 -070033#include <media/stagefright/foundation/ABuffer.h>
34#include <media/stagefright/foundation/AMessage.h>
35#include <media/stagefright/MetaData.h>
36#include <media/stagefright/NuMediaExtractor.h>
37#include <media/IMediaHTTPService.h>
Marco Nelissen0c3be872014-05-01 10:14:44 -070038#include <android_util_Binder.h>
39
40#include <jni.h>
41
42using namespace android;
43
Marco Nelissen0c3be872014-05-01 10:14:44 -070044struct AMediaExtractor {
45 sp<NuMediaExtractor> mImpl;
Marco Nelissen050eb322014-05-09 15:10:23 -070046 sp<ABuffer> mPsshBuf;
Marco Nelissen0c3be872014-05-01 10:14:44 -070047};
48
Robert Shih0b4530d2019-01-18 12:12:03 -080049sp<ABuffer> U32ArrayToSizeBuf(size_t numSubSamples, uint32_t *data) {
50 if (numSubSamples > SIZE_MAX / sizeof(size_t)) {
51 return NULL;
52 }
53 sp<ABuffer> sizebuf = new ABuffer(numSubSamples * sizeof(size_t));
54 size_t *sizes = (size_t *)sizebuf->data();
55 for (size_t i = 0; sizes != NULL && i < numSubSamples; i++) {
56 sizes[i] = data[i];
57 }
58 return sizebuf;
59}
60
Marco Nelissen0c3be872014-05-01 10:14:44 -070061extern "C" {
62
Marco Nelissen3425fd52014-05-14 11:12:46 -070063EXPORT
Marco Nelissen0c3be872014-05-01 10:14:44 -070064AMediaExtractor* AMediaExtractor_new() {
65 ALOGV("ctor");
66 AMediaExtractor *mData = new AMediaExtractor();
Santiago Seifert1349f472020-11-11 23:49:28 +000067 mData->mImpl = new NuMediaExtractor(
68 NdkJavaVMHelper::getJNIEnv() != nullptr
69 ? NuMediaExtractor::EntryPoint::NDK_WITH_JVM
70 : NuMediaExtractor::EntryPoint::NDK_NO_JVM );
Marco Nelissen0c3be872014-05-01 10:14:44 -070071 return mData;
72}
73
Marco Nelissen3425fd52014-05-14 11:12:46 -070074EXPORT
Marco Nelissene419d7c2014-05-15 14:17:25 -070075media_status_t AMediaExtractor_delete(AMediaExtractor *mData) {
Marco Nelissen0c3be872014-05-01 10:14:44 -070076 ALOGV("dtor");
77 delete mData;
Marco Nelissene419d7c2014-05-15 14:17:25 -070078 return AMEDIA_OK;
Marco Nelissen0c3be872014-05-01 10:14:44 -070079}
80
Marco Nelissen3425fd52014-05-14 11:12:46 -070081EXPORT
Glenn Kastenb187de12014-12-30 08:18:15 -080082media_status_t AMediaExtractor_setDataSourceFd(AMediaExtractor *mData, int fd, off64_t offset,
83 off64_t length) {
Aurimas Liutikas214c8332016-02-19 14:48:23 -080084 ALOGV("setDataSource(%d, %" PRId64 ", %" PRId64 ")", fd, offset, length);
Marco Nelissene419d7c2014-05-15 14:17:25 -070085 return translate_error(mData->mImpl->setDataSource(fd, offset, length));
Marco Nelissen0c3be872014-05-01 10:14:44 -070086}
87
Robert Shih6a59e4a2018-08-30 13:31:28 -070088media_status_t AMediaExtractor_setDataSourceWithHeaders(AMediaExtractor *mData,
89 const char *uri,
90 int numheaders,
91 const char * const *keys,
92 const char * const *values) {
93
94 ALOGV("setDataSource(%s)", uri);
Marco Nelissen0c3be872014-05-01 10:14:44 -070095
Marco Nelissena5232042019-09-24 09:27:40 -070096 sp<MediaHTTPService> httpService = createMediaHttpService(uri);
Robert Shih730af222018-09-14 14:02:57 -070097 if (httpService == NULL) {
98 ALOGE("can't create http service");
Marco Nelissene419d7c2014-05-15 14:17:25 -070099 return AMEDIA_ERROR_UNSUPPORTED;
Marco Nelissen0c3be872014-05-01 10:14:44 -0700100 }
101
Robert Shih6a59e4a2018-08-30 13:31:28 -0700102 KeyedVector<String8, String8> headers;
103 for (int i = 0; i < numheaders; ++i) {
104 String8 key8(keys[i]);
105 String8 value8(values[i]);
106 headers.add(key8, value8);
107 }
108
109 status_t err;
110 err = mData->mImpl->setDataSource(httpService, uri, numheaders > 0 ? &headers : NULL);
Marco Nelissene419d7c2014-05-15 14:17:25 -0700111 return translate_error(err);
Marco Nelissen0c3be872014-05-01 10:14:44 -0700112}
113
Marco Nelissen3425fd52014-05-14 11:12:46 -0700114EXPORT
Robert Shih82248d12018-10-03 15:57:47 -0700115media_status_t AMediaExtractor_setDataSource(AMediaExtractor *mData, const char *location) {
116 return AMediaExtractor_setDataSourceWithHeaders(mData, location, 0, NULL, NULL);
117}
118
119EXPORT
Robert Shih0df451b2017-12-08 14:16:50 -0800120media_status_t AMediaExtractor_setDataSourceCustom(AMediaExtractor* mData, AMediaDataSource *src) {
121 return translate_error(mData->mImpl->setDataSource(new NdkDataSource(src)));
122}
123
124EXPORT
Robert Shih30e3c7d2018-01-21 17:06:12 -0800125AMediaFormat* AMediaExtractor_getFileFormat(AMediaExtractor *mData) {
126 sp<AMessage> format;
127 mData->mImpl->getFileFormat(&format);
128 return AMediaFormat_fromMsg(&format);
129}
130
131EXPORT
Marco Nelissene419d7c2014-05-15 14:17:25 -0700132size_t AMediaExtractor_getTrackCount(AMediaExtractor *mData) {
Marco Nelissen0c3be872014-05-01 10:14:44 -0700133 return mData->mImpl->countTracks();
134}
135
Marco Nelissen3425fd52014-05-14 11:12:46 -0700136EXPORT
Marco Nelissen0c3be872014-05-01 10:14:44 -0700137AMediaFormat* AMediaExtractor_getTrackFormat(AMediaExtractor *mData, size_t idx) {
138 sp<AMessage> format;
139 mData->mImpl->getTrackFormat(idx, &format);
140 return AMediaFormat_fromMsg(&format);
141}
142
Marco Nelissen3425fd52014-05-14 11:12:46 -0700143EXPORT
Marco Nelissene419d7c2014-05-15 14:17:25 -0700144media_status_t AMediaExtractor_selectTrack(AMediaExtractor *mData, size_t idx) {
Mark Salyzyn98f28cd2014-06-18 16:32:50 -0700145 ALOGV("selectTrack(%zu)", idx);
Marco Nelissen0c3be872014-05-01 10:14:44 -0700146 return translate_error(mData->mImpl->selectTrack(idx));
147}
148
Marco Nelissen3425fd52014-05-14 11:12:46 -0700149EXPORT
Marco Nelissene419d7c2014-05-15 14:17:25 -0700150media_status_t AMediaExtractor_unselectTrack(AMediaExtractor *mData, size_t idx) {
Mark Salyzyn98f28cd2014-06-18 16:32:50 -0700151 ALOGV("unselectTrack(%zu)", idx);
Marco Nelissen0c3be872014-05-01 10:14:44 -0700152 return translate_error(mData->mImpl->unselectTrack(idx));
153}
154
Marco Nelissen3425fd52014-05-14 11:12:46 -0700155EXPORT
Marco Nelissen0c3be872014-05-01 10:14:44 -0700156bool AMediaExtractor_advance(AMediaExtractor *mData) {
157 //ALOGV("advance");
Robert Shih70452262016-09-16 16:43:49 -0700158 status_t err = mData->mImpl->advance();
159 if (err == ERROR_END_OF_STREAM) {
160 return false;
161 } else if (err != OK) {
162 ALOGE("sf error code: %d", err);
163 return false;
164 }
165 return true;
Marco Nelissen0c3be872014-05-01 10:14:44 -0700166}
167
Marco Nelissen3425fd52014-05-14 11:12:46 -0700168EXPORT
Marco Nelissen79e2b622014-05-16 08:07:28 -0700169media_status_t AMediaExtractor_seekTo(AMediaExtractor *ex, int64_t seekPosUs, SeekMode mode) {
170 android::MediaSource::ReadOptions::SeekMode sfmode;
171 if (mode == AMEDIAEXTRACTOR_SEEK_PREVIOUS_SYNC) {
172 sfmode = android::MediaSource::ReadOptions::SEEK_PREVIOUS_SYNC;
173 } else if (mode == AMEDIAEXTRACTOR_SEEK_CLOSEST_SYNC) {
174 sfmode = android::MediaSource::ReadOptions::SEEK_CLOSEST_SYNC;
175 } else {
176 sfmode = android::MediaSource::ReadOptions::SEEK_NEXT_SYNC;
177 }
178
179 return translate_error(ex->mImpl->seekTo(seekPosUs, sfmode));
180}
181
182EXPORT
Marco Nelissene419d7c2014-05-15 14:17:25 -0700183ssize_t AMediaExtractor_readSampleData(AMediaExtractor *mData, uint8_t *buffer, size_t capacity) {
Marco Nelissen0c3be872014-05-01 10:14:44 -0700184 //ALOGV("readSampleData");
185 sp<ABuffer> tmp = new ABuffer(buffer, capacity);
186 if (mData->mImpl->readSampleData(tmp) == OK) {
187 return tmp->size();
188 }
189 return -1;
190}
191
Marco Nelissen3425fd52014-05-14 11:12:46 -0700192EXPORT
Robert Shih30e3c7d2018-01-21 17:06:12 -0800193ssize_t AMediaExtractor_getSampleSize(AMediaExtractor *mData) {
194 size_t sampleSize;
195 status_t err = mData->mImpl->getSampleSize(&sampleSize);
196 if (err != OK) {
197 return -1;
198 }
199 return sampleSize;
200}
201
202EXPORT
Marco Nelissene419d7c2014-05-15 14:17:25 -0700203uint32_t AMediaExtractor_getSampleFlags(AMediaExtractor *mData) {
Marco Nelissen0c3be872014-05-01 10:14:44 -0700204 int sampleFlags = 0;
205 sp<MetaData> meta;
206 status_t err = mData->mImpl->getSampleMeta(&meta);
207 if (err != OK) {
208 return -1;
209 }
210 int32_t val;
211 if (meta->findInt32(kKeyIsSyncFrame, &val) && val != 0) {
Marco Nelissene419d7c2014-05-15 14:17:25 -0700212 sampleFlags |= AMEDIAEXTRACTOR_SAMPLE_FLAG_SYNC;
Marco Nelissen0c3be872014-05-01 10:14:44 -0700213 }
214
215 uint32_t type;
216 const void *data;
217 size_t size;
218 if (meta->findData(kKeyEncryptedSizes, &type, &data, &size)) {
Marco Nelissene419d7c2014-05-15 14:17:25 -0700219 sampleFlags |= AMEDIAEXTRACTOR_SAMPLE_FLAG_ENCRYPTED;
Marco Nelissen0c3be872014-05-01 10:14:44 -0700220 }
221 return sampleFlags;
222}
223
Marco Nelissen3425fd52014-05-14 11:12:46 -0700224EXPORT
Marco Nelissen0c3be872014-05-01 10:14:44 -0700225int AMediaExtractor_getSampleTrackIndex(AMediaExtractor *mData) {
226 size_t idx;
227 if (mData->mImpl->getSampleTrackIndex(&idx) != OK) {
228 return -1;
229 }
230 return idx;
231}
232
Marco Nelissen3425fd52014-05-14 11:12:46 -0700233EXPORT
Marco Nelisseneb4860c2014-05-29 08:04:34 -0700234int64_t AMediaExtractor_getSampleTime(AMediaExtractor *mData) {
Marco Nelissen0c3be872014-05-01 10:14:44 -0700235 int64_t time;
236 if (mData->mImpl->getSampleTime(&time) != OK) {
237 return -1;
238 }
239 return time;
240}
241
Marco Nelissen3425fd52014-05-14 11:12:46 -0700242EXPORT
Marco Nelissen050eb322014-05-09 15:10:23 -0700243PsshInfo* AMediaExtractor_getPsshInfo(AMediaExtractor *ex) {
244
245 if (ex->mPsshBuf != NULL) {
246 return (PsshInfo*) ex->mPsshBuf->data();
247 }
248
249 sp<AMessage> format;
250 ex->mImpl->getFileFormat(&format);
251 sp<ABuffer> buffer;
252 if(!format->findBuffer("pssh", &buffer)) {
253 return NULL;
254 }
255
256 // the format of the buffer is 1 or more of:
257 // {
258 // 16 byte uuid
259 // 4 byte data length N
260 // N bytes of data
261 // }
262
263 // Determine the number of entries in the source data.
264 // Since we got the data from stagefright, we trust it is valid and properly formatted.
265 const uint8_t* data = buffer->data();
266 size_t len = buffer->size();
267 size_t numentries = 0;
268 while (len > 0) {
269 numentries++;
270
Marco Nelissen346bb512015-04-09 14:32:45 -0700271 if (len < 16) {
272 ALOGE("invalid PSSH data");
273 return NULL;
274 }
Marco Nelissen050eb322014-05-09 15:10:23 -0700275 // skip uuid
276 data += 16;
277 len -= 16;
278
279 // get data length
Marco Nelissen346bb512015-04-09 14:32:45 -0700280 if (len < 4) {
281 ALOGE("invalid PSSH data");
282 return NULL;
283 }
Marco Nelissen050eb322014-05-09 15:10:23 -0700284 uint32_t datalen = *((uint32_t*)data);
285 data += 4;
286 len -= 4;
287
Marco Nelissen346bb512015-04-09 14:32:45 -0700288 if (len < datalen) {
289 ALOGE("invalid PSSH data");
290 return NULL;
291 }
Marco Nelissen050eb322014-05-09 15:10:23 -0700292 // skip the data
293 data += datalen;
294 len -= datalen;
295 }
296
Marco Nelissen58344bc2014-10-23 11:36:38 -0700297 // there are <numentries> in the source buffer, we need
298 // (source buffer size) - (sizeof(uint32_t) * numentries) + sizeof(size_t)
299 // + ((sizeof(void*) + sizeof(size_t)) * numentries) bytes for the PsshInfo structure
300 // Or in other words, the data lengths in the source structure are replaced by size_t
301 // (which may be the same size or larger, for 64 bit), and in addition there is an
302 // extra pointer for each entry, and an extra size_t for the entire PsshInfo.
303 size_t newsize = buffer->size() - (sizeof(uint32_t) * numentries) + sizeof(size_t)
304 + ((sizeof(void*) + sizeof(size_t)) * numentries);
Marco Nelissen346bb512015-04-09 14:32:45 -0700305 if (newsize <= buffer->size()) {
306 ALOGE("invalid PSSH data");
307 return NULL;
308 }
Marco Nelissen050eb322014-05-09 15:10:23 -0700309 ex->mPsshBuf = new ABuffer(newsize);
310 ex->mPsshBuf->setRange(0, newsize);
311
312 // copy data
313 const uint8_t* src = buffer->data();
314 uint8_t* dst = ex->mPsshBuf->data();
Marco Nelissen58344bc2014-10-23 11:36:38 -0700315 uint8_t* dstdata = dst + sizeof(size_t) + numentries * sizeof(PsshEntry);
316 *((size_t*)dst) = numentries;
317 dst += sizeof(size_t);
Marco Nelissen050eb322014-05-09 15:10:23 -0700318 for (size_t i = 0; i < numentries; i++) {
319 // copy uuid
320 memcpy(dst, src, 16);
321 src += 16;
322 dst += 16;
323
324 // get/copy data length
325 uint32_t datalen = *((uint32_t*)src);
Marco Nelissen58344bc2014-10-23 11:36:38 -0700326 *((size_t*)dst) = datalen;
327 src += sizeof(uint32_t);
328 dst += sizeof(size_t);
Marco Nelissen050eb322014-05-09 15:10:23 -0700329
330 // the next entry in the destination is a pointer to the actual data, which we store
331 // after the array of PsshEntry
Marco Nelissen58344bc2014-10-23 11:36:38 -0700332 *((void**)dst) = dstdata;
333 dst += sizeof(void*);
Marco Nelissen050eb322014-05-09 15:10:23 -0700334
335 // copy the actual data
336 memcpy(dstdata, src, datalen);
337 dstdata += datalen;
338 src += datalen;
339 }
340
341 return (PsshInfo*) ex->mPsshBuf->data();
342}
343
Marco Nelissen3425fd52014-05-14 11:12:46 -0700344EXPORT
Marco Nelissen050eb322014-05-09 15:10:23 -0700345AMediaCodecCryptoInfo *AMediaExtractor_getSampleCryptoInfo(AMediaExtractor *ex) {
346 sp<MetaData> meta;
347 if(ex->mImpl->getSampleMeta(&meta) != 0) {
348 return NULL;
349 }
350
351 uint32_t type;
352 const void *crypteddata;
353 size_t cryptedsize;
354 if (!meta->findData(kKeyEncryptedSizes, &type, &crypteddata, &cryptedsize)) {
355 return NULL;
356 }
Robert Shih0b4530d2019-01-18 12:12:03 -0800357 size_t numSubSamples = cryptedsize / sizeof(uint32_t);
Marco Nelissen050eb322014-05-09 15:10:23 -0700358
359 const void *cleardata;
360 size_t clearsize;
361 if (meta->findData(kKeyPlainSizes, &type, &cleardata, &clearsize)) {
362 if (clearsize != cryptedsize) {
363 // The two must be of the same length.
364 return NULL;
365 }
366 }
367
368 const void *key;
369 size_t keysize;
Edwin Wongb2fb3c92016-08-29 14:57:47 -0700370 if (meta->findData(kKeyCryptoKey, &type, &key, &keysize)) {
Marco Nelissen050eb322014-05-09 15:10:23 -0700371 if (keysize != 16) {
Edwin Wongb2fb3c92016-08-29 14:57:47 -0700372 // Keys must be 16 bytes in length.
Marco Nelissen050eb322014-05-09 15:10:23 -0700373 return NULL;
374 }
375 }
376
377 const void *iv;
378 size_t ivsize;
379 if (meta->findData(kKeyCryptoIV, &type, &iv, &ivsize)) {
380 if (ivsize != 16) {
381 // IVs must be 16 bytes in length.
382 return NULL;
383 }
384 }
385
386 int32_t mode;
387 if (!meta->findInt32(kKeyCryptoMode, &mode)) {
388 mode = CryptoPlugin::kMode_AES_CTR;
389 }
390
Robert Shih0b4530d2019-01-18 12:12:03 -0800391 if (sizeof(uint32_t) != sizeof(size_t)) {
392 sp<ABuffer> clearbuf = U32ArrayToSizeBuf(numSubSamples, (uint32_t *)cleardata);
393 sp<ABuffer> cryptedbuf = U32ArrayToSizeBuf(numSubSamples, (uint32_t *)crypteddata);
394 cleardata = clearbuf == NULL ? NULL : clearbuf->data();
395 crypteddata = crypteddata == NULL ? NULL : cryptedbuf->data();
396 if(crypteddata == NULL || cleardata == NULL) {
397 return NULL;
398 }
399 }
400
Marco Nelissen050eb322014-05-09 15:10:23 -0700401 return AMediaCodecCryptoInfo_new(
402 numSubSamples,
403 (uint8_t*) key,
404 (uint8_t*) iv,
Marco Nelissen79e2b622014-05-16 08:07:28 -0700405 (cryptoinfo_mode_t) mode,
Marco Nelissen050eb322014-05-09 15:10:23 -0700406 (size_t*) cleardata,
407 (size_t*) crypteddata);
408}
409
Robert Shih30e3c7d2018-01-21 17:06:12 -0800410EXPORT
411int64_t AMediaExtractor_getCachedDuration(AMediaExtractor *ex) {
412 bool eos;
413 int64_t durationUs;
414 if (ex->mImpl->getCachedDuration(&durationUs, &eos)) {
415 return durationUs;
416 }
417 return -1;
418}
Marco Nelissen0c3be872014-05-01 10:14:44 -0700419
Robert Shihd83d4f42018-02-24 19:02:46 -0800420EXPORT
421media_status_t AMediaExtractor_getSampleFormat(AMediaExtractor *ex, AMediaFormat *fmt) {
422 if (fmt == NULL) {
423 return AMEDIA_ERROR_INVALID_PARAMETER;
424 }
425
426 sp<MetaData> sampleMeta;
427 status_t err = ex->mImpl->getSampleMeta(&sampleMeta);
428 if (err != OK) {
429 return translate_error(err);
430 }
431
432 sp<AMessage> meta;
433 AMediaFormat_getFormat(fmt, &meta);
434 meta->clear();
435
436 int32_t layerId;
437 if (sampleMeta->findInt32(kKeyTemporalLayerId, &layerId)) {
438 meta->setInt32(AMEDIAFORMAT_KEY_TEMPORAL_LAYER_ID, layerId);
439 }
440
441 size_t trackIndex;
442 err = ex->mImpl->getSampleTrackIndex(&trackIndex);
443 if (err == OK) {
444 meta->setInt32(AMEDIAFORMAT_KEY_TRACK_INDEX, trackIndex);
445 sp<AMessage> trackFormat;
446 AString mime;
447 err = ex->mImpl->getTrackFormat(trackIndex, &trackFormat);
448 if (err == OK
449 && trackFormat != NULL
450 && trackFormat->findString(AMEDIAFORMAT_KEY_MIME, &mime)) {
451 meta->setString(AMEDIAFORMAT_KEY_MIME, mime);
452 }
453 }
454
455 int64_t durationUs;
456 if (sampleMeta->findInt64(kKeyDuration, &durationUs)) {
457 meta->setInt64(AMEDIAFORMAT_KEY_DURATION, durationUs);
458 }
459
460 uint32_t dataType; // unused
461 const void *seiData;
462 size_t seiLength;
463 if (sampleMeta->findData(kKeySEI, &dataType, &seiData, &seiLength)) {
464 sp<ABuffer> sei = ABuffer::CreateAsCopy(seiData, seiLength);;
465 meta->setBuffer(AMEDIAFORMAT_KEY_SEI, sei);
466 }
467
468 const void *mpegUserDataPointer;
469 size_t mpegUserDataLength;
470 if (sampleMeta->findData(
471 kKeyMpegUserData, &dataType, &mpegUserDataPointer, &mpegUserDataLength)) {
472 sp<ABuffer> mpegUserData = ABuffer::CreateAsCopy(mpegUserDataPointer, mpegUserDataLength);
473 meta->setBuffer(AMEDIAFORMAT_KEY_MPEG_USER_DATA, mpegUserData);
474 }
475
Sampath Shettyc6148a62018-12-18 15:50:43 +1100476 const void *audioPresentationsPointer;
477 size_t audioPresentationsLength;
478 if (sampleMeta->findData(
479 kKeyAudioPresentationInfo, &dataType,
480 &audioPresentationsPointer, &audioPresentationsLength)) {
481 sp<ABuffer> audioPresentationsData = ABuffer::CreateAsCopy(
482 audioPresentationsPointer, audioPresentationsLength);
483 meta->setBuffer(AMEDIAFORMAT_KEY_AUDIO_PRESENTATION_INFO, audioPresentationsData);
484 }
485
Robert Shihd83d4f42018-02-24 19:02:46 -0800486 return AMEDIA_OK;
487}
488
Marco Nelissen0c3be872014-05-01 10:14:44 -0700489} // extern "C"
490