blob: fa1292e7c23a7285596e8e01532ddc62e451edca [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>
Robert Shih0df451b2017-12-08 14:16:50 -080023#include "NdkMediaDataSourcePriv.h"
Marco Nelissen0c3be872014-05-01 10:14:44 -070024#include "NdkMediaFormatPriv.h"
25
26
Aurimas Liutikas214c8332016-02-19 14:48:23 -080027#include <inttypes.h>
Marco Nelissen0c3be872014-05-01 10:14:44 -070028#include <utils/Log.h>
29#include <utils/StrongPointer.h>
Marco Nelissen050eb322014-05-09 15:10:23 -070030#include <media/hardware/CryptoAPI.h>
Marco Nelissen0c3be872014-05-01 10:14:44 -070031#include <media/stagefright/foundation/ABuffer.h>
32#include <media/stagefright/foundation/AMessage.h>
33#include <media/stagefright/MetaData.h>
34#include <media/stagefright/NuMediaExtractor.h>
35#include <media/IMediaHTTPService.h>
36#include <android_runtime/AndroidRuntime.h>
37#include <android_util_Binder.h>
38
39#include <jni.h>
40
41using namespace android;
42
Marco Nelissene419d7c2014-05-15 14:17:25 -070043static media_status_t translate_error(status_t err) {
Marco Nelissen0c3be872014-05-01 10:14:44 -070044 if (err == OK) {
Marco Nelissene419d7c2014-05-15 14:17:25 -070045 return AMEDIA_OK;
Robert Shihd83d4f42018-02-24 19:02:46 -080046 } else if (err == ERROR_END_OF_STREAM) {
47 return AMEDIA_ERROR_END_OF_STREAM;
48 } else if (err == ERROR_IO) {
49 return AMEDIA_ERROR_IO;
Marco Nelissen0c3be872014-05-01 10:14:44 -070050 }
Robert Shihd83d4f42018-02-24 19:02:46 -080051
Marco Nelissen0c3be872014-05-01 10:14:44 -070052 ALOGE("sf error code: %d", err);
Marco Nelissene419d7c2014-05-15 14:17:25 -070053 return AMEDIA_ERROR_UNKNOWN;
Marco Nelissen0c3be872014-05-01 10:14:44 -070054}
55
56struct AMediaExtractor {
57 sp<NuMediaExtractor> mImpl;
Marco Nelissen050eb322014-05-09 15:10:23 -070058 sp<ABuffer> mPsshBuf;
Marco Nelissen0c3be872014-05-01 10:14:44 -070059};
60
61extern "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();
67 mData->mImpl = new NuMediaExtractor();
68 return mData;
69}
70
Marco Nelissen3425fd52014-05-14 11:12:46 -070071EXPORT
Marco Nelissene419d7c2014-05-15 14:17:25 -070072media_status_t AMediaExtractor_delete(AMediaExtractor *mData) {
Marco Nelissen0c3be872014-05-01 10:14:44 -070073 ALOGV("dtor");
74 delete mData;
Marco Nelissene419d7c2014-05-15 14:17:25 -070075 return AMEDIA_OK;
Marco Nelissen0c3be872014-05-01 10:14:44 -070076}
77
Marco Nelissen3425fd52014-05-14 11:12:46 -070078EXPORT
Glenn Kastenb187de12014-12-30 08:18:15 -080079media_status_t AMediaExtractor_setDataSourceFd(AMediaExtractor *mData, int fd, off64_t offset,
80 off64_t length) {
Aurimas Liutikas214c8332016-02-19 14:48:23 -080081 ALOGV("setDataSource(%d, %" PRId64 ", %" PRId64 ")", fd, offset, length);
Marco Nelissene419d7c2014-05-15 14:17:25 -070082 return translate_error(mData->mImpl->setDataSource(fd, offset, length));
Marco Nelissen0c3be872014-05-01 10:14:44 -070083}
84
Marco Nelissen3425fd52014-05-14 11:12:46 -070085EXPORT
Marco Nelissene419d7c2014-05-15 14:17:25 -070086media_status_t AMediaExtractor_setDataSource(AMediaExtractor *mData, const char *location) {
Robert Shih6a59e4a2018-08-30 13:31:28 -070087 return AMediaExtractor_setDataSourceWithHeaders(mData, location, 0, NULL, NULL);
88}
89
90EXPORT
91media_status_t AMediaExtractor_setDataSourceWithHeaders(AMediaExtractor *mData,
92 const char *uri,
93 int numheaders,
94 const char * const *keys,
95 const char * const *values) {
96
97 ALOGV("setDataSource(%s)", uri);
Marco Nelissen0c3be872014-05-01 10:14:44 -070098
99 JNIEnv *env = AndroidRuntime::getJNIEnv();
100 jobject service = NULL;
101 if (env == NULL) {
102 ALOGE("setDataSource(path) must be called from Java thread");
Marco Nelissene419d7c2014-05-15 14:17:25 -0700103 return AMEDIA_ERROR_UNSUPPORTED;
Marco Nelissen0c3be872014-05-01 10:14:44 -0700104 }
105
106 jclass mediahttpclass = env->FindClass("android/media/MediaHTTPService");
107 if (mediahttpclass == NULL) {
108 ALOGE("can't find MediaHttpService");
109 env->ExceptionClear();
Marco Nelissene419d7c2014-05-15 14:17:25 -0700110 return AMEDIA_ERROR_UNSUPPORTED;
Marco Nelissen0c3be872014-05-01 10:14:44 -0700111 }
112
113 jmethodID mediaHttpCreateMethod = env->GetStaticMethodID(mediahttpclass,
114 "createHttpServiceBinderIfNecessary", "(Ljava/lang/String;)Landroid/os/IBinder;");
115 if (mediaHttpCreateMethod == NULL) {
116 ALOGE("can't find method");
117 env->ExceptionClear();
Marco Nelissene419d7c2014-05-15 14:17:25 -0700118 return AMEDIA_ERROR_UNSUPPORTED;
Marco Nelissen0c3be872014-05-01 10:14:44 -0700119 }
120
Robert Shih6a59e4a2018-08-30 13:31:28 -0700121 jstring jloc = env->NewStringUTF(uri);
Marco Nelissen0c3be872014-05-01 10:14:44 -0700122
123 service = env->CallStaticObjectMethod(mediahttpclass, mediaHttpCreateMethod, jloc);
124 env->DeleteLocalRef(jloc);
125
126 sp<IMediaHTTPService> httpService;
127 if (service != NULL) {
128 sp<IBinder> binder = ibinderForJavaObject(env, service);
129 httpService = interface_cast<IMediaHTTPService>(binder);
130 }
131
Robert Shih6a59e4a2018-08-30 13:31:28 -0700132 KeyedVector<String8, String8> headers;
133 for (int i = 0; i < numheaders; ++i) {
134 String8 key8(keys[i]);
135 String8 value8(values[i]);
136 headers.add(key8, value8);
137 }
138
139 status_t err;
140 err = mData->mImpl->setDataSource(httpService, uri, numheaders > 0 ? &headers : NULL);
Marco Nelissen0c3be872014-05-01 10:14:44 -0700141 env->ExceptionClear();
Marco Nelissene419d7c2014-05-15 14:17:25 -0700142 return translate_error(err);
Marco Nelissen0c3be872014-05-01 10:14:44 -0700143}
144
Marco Nelissen3425fd52014-05-14 11:12:46 -0700145EXPORT
Robert Shih0df451b2017-12-08 14:16:50 -0800146media_status_t AMediaExtractor_setDataSourceCustom(AMediaExtractor* mData, AMediaDataSource *src) {
147 return translate_error(mData->mImpl->setDataSource(new NdkDataSource(src)));
148}
149
150EXPORT
Robert Shih30e3c7d2018-01-21 17:06:12 -0800151AMediaFormat* AMediaExtractor_getFileFormat(AMediaExtractor *mData) {
152 sp<AMessage> format;
153 mData->mImpl->getFileFormat(&format);
154 return AMediaFormat_fromMsg(&format);
155}
156
157EXPORT
Marco Nelissene419d7c2014-05-15 14:17:25 -0700158size_t AMediaExtractor_getTrackCount(AMediaExtractor *mData) {
Marco Nelissen0c3be872014-05-01 10:14:44 -0700159 return mData->mImpl->countTracks();
160}
161
Marco Nelissen3425fd52014-05-14 11:12:46 -0700162EXPORT
Marco Nelissen0c3be872014-05-01 10:14:44 -0700163AMediaFormat* AMediaExtractor_getTrackFormat(AMediaExtractor *mData, size_t idx) {
164 sp<AMessage> format;
165 mData->mImpl->getTrackFormat(idx, &format);
166 return AMediaFormat_fromMsg(&format);
167}
168
Marco Nelissen3425fd52014-05-14 11:12:46 -0700169EXPORT
Marco Nelissene419d7c2014-05-15 14:17:25 -0700170media_status_t AMediaExtractor_selectTrack(AMediaExtractor *mData, size_t idx) {
Mark Salyzyn98f28cd2014-06-18 16:32:50 -0700171 ALOGV("selectTrack(%zu)", idx);
Marco Nelissen0c3be872014-05-01 10:14:44 -0700172 return translate_error(mData->mImpl->selectTrack(idx));
173}
174
Marco Nelissen3425fd52014-05-14 11:12:46 -0700175EXPORT
Marco Nelissene419d7c2014-05-15 14:17:25 -0700176media_status_t AMediaExtractor_unselectTrack(AMediaExtractor *mData, size_t idx) {
Mark Salyzyn98f28cd2014-06-18 16:32:50 -0700177 ALOGV("unselectTrack(%zu)", idx);
Marco Nelissen0c3be872014-05-01 10:14:44 -0700178 return translate_error(mData->mImpl->unselectTrack(idx));
179}
180
Marco Nelissen3425fd52014-05-14 11:12:46 -0700181EXPORT
Marco Nelissen0c3be872014-05-01 10:14:44 -0700182bool AMediaExtractor_advance(AMediaExtractor *mData) {
183 //ALOGV("advance");
Robert Shih70452262016-09-16 16:43:49 -0700184 status_t err = mData->mImpl->advance();
185 if (err == ERROR_END_OF_STREAM) {
186 return false;
187 } else if (err != OK) {
188 ALOGE("sf error code: %d", err);
189 return false;
190 }
191 return true;
Marco Nelissen0c3be872014-05-01 10:14:44 -0700192}
193
Marco Nelissen3425fd52014-05-14 11:12:46 -0700194EXPORT
Marco Nelissen79e2b622014-05-16 08:07:28 -0700195media_status_t AMediaExtractor_seekTo(AMediaExtractor *ex, int64_t seekPosUs, SeekMode mode) {
196 android::MediaSource::ReadOptions::SeekMode sfmode;
197 if (mode == AMEDIAEXTRACTOR_SEEK_PREVIOUS_SYNC) {
198 sfmode = android::MediaSource::ReadOptions::SEEK_PREVIOUS_SYNC;
199 } else if (mode == AMEDIAEXTRACTOR_SEEK_CLOSEST_SYNC) {
200 sfmode = android::MediaSource::ReadOptions::SEEK_CLOSEST_SYNC;
201 } else {
202 sfmode = android::MediaSource::ReadOptions::SEEK_NEXT_SYNC;
203 }
204
205 return translate_error(ex->mImpl->seekTo(seekPosUs, sfmode));
206}
207
208EXPORT
Marco Nelissene419d7c2014-05-15 14:17:25 -0700209ssize_t AMediaExtractor_readSampleData(AMediaExtractor *mData, uint8_t *buffer, size_t capacity) {
Marco Nelissen0c3be872014-05-01 10:14:44 -0700210 //ALOGV("readSampleData");
211 sp<ABuffer> tmp = new ABuffer(buffer, capacity);
212 if (mData->mImpl->readSampleData(tmp) == OK) {
213 return tmp->size();
214 }
215 return -1;
216}
217
Marco Nelissen3425fd52014-05-14 11:12:46 -0700218EXPORT
Robert Shih30e3c7d2018-01-21 17:06:12 -0800219ssize_t AMediaExtractor_getSampleSize(AMediaExtractor *mData) {
220 size_t sampleSize;
221 status_t err = mData->mImpl->getSampleSize(&sampleSize);
222 if (err != OK) {
223 return -1;
224 }
225 return sampleSize;
226}
227
228EXPORT
Marco Nelissene419d7c2014-05-15 14:17:25 -0700229uint32_t AMediaExtractor_getSampleFlags(AMediaExtractor *mData) {
Marco Nelissen0c3be872014-05-01 10:14:44 -0700230 int sampleFlags = 0;
231 sp<MetaData> meta;
232 status_t err = mData->mImpl->getSampleMeta(&meta);
233 if (err != OK) {
234 return -1;
235 }
236 int32_t val;
237 if (meta->findInt32(kKeyIsSyncFrame, &val) && val != 0) {
Marco Nelissene419d7c2014-05-15 14:17:25 -0700238 sampleFlags |= AMEDIAEXTRACTOR_SAMPLE_FLAG_SYNC;
Marco Nelissen0c3be872014-05-01 10:14:44 -0700239 }
240
241 uint32_t type;
242 const void *data;
243 size_t size;
244 if (meta->findData(kKeyEncryptedSizes, &type, &data, &size)) {
Marco Nelissene419d7c2014-05-15 14:17:25 -0700245 sampleFlags |= AMEDIAEXTRACTOR_SAMPLE_FLAG_ENCRYPTED;
Marco Nelissen0c3be872014-05-01 10:14:44 -0700246 }
247 return sampleFlags;
248}
249
Marco Nelissen3425fd52014-05-14 11:12:46 -0700250EXPORT
Marco Nelissen0c3be872014-05-01 10:14:44 -0700251int AMediaExtractor_getSampleTrackIndex(AMediaExtractor *mData) {
252 size_t idx;
253 if (mData->mImpl->getSampleTrackIndex(&idx) != OK) {
254 return -1;
255 }
256 return idx;
257}
258
Marco Nelissen3425fd52014-05-14 11:12:46 -0700259EXPORT
Marco Nelisseneb4860c2014-05-29 08:04:34 -0700260int64_t AMediaExtractor_getSampleTime(AMediaExtractor *mData) {
Marco Nelissen0c3be872014-05-01 10:14:44 -0700261 int64_t time;
262 if (mData->mImpl->getSampleTime(&time) != OK) {
263 return -1;
264 }
265 return time;
266}
267
Marco Nelissen3425fd52014-05-14 11:12:46 -0700268EXPORT
Marco Nelissen050eb322014-05-09 15:10:23 -0700269PsshInfo* AMediaExtractor_getPsshInfo(AMediaExtractor *ex) {
270
271 if (ex->mPsshBuf != NULL) {
272 return (PsshInfo*) ex->mPsshBuf->data();
273 }
274
275 sp<AMessage> format;
276 ex->mImpl->getFileFormat(&format);
277 sp<ABuffer> buffer;
278 if(!format->findBuffer("pssh", &buffer)) {
279 return NULL;
280 }
281
282 // the format of the buffer is 1 or more of:
283 // {
284 // 16 byte uuid
285 // 4 byte data length N
286 // N bytes of data
287 // }
288
289 // Determine the number of entries in the source data.
290 // Since we got the data from stagefright, we trust it is valid and properly formatted.
291 const uint8_t* data = buffer->data();
292 size_t len = buffer->size();
293 size_t numentries = 0;
294 while (len > 0) {
295 numentries++;
296
Marco Nelissen346bb512015-04-09 14:32:45 -0700297 if (len < 16) {
298 ALOGE("invalid PSSH data");
299 return NULL;
300 }
Marco Nelissen050eb322014-05-09 15:10:23 -0700301 // skip uuid
302 data += 16;
303 len -= 16;
304
305 // get data length
Marco Nelissen346bb512015-04-09 14:32:45 -0700306 if (len < 4) {
307 ALOGE("invalid PSSH data");
308 return NULL;
309 }
Marco Nelissen050eb322014-05-09 15:10:23 -0700310 uint32_t datalen = *((uint32_t*)data);
311 data += 4;
312 len -= 4;
313
Marco Nelissen346bb512015-04-09 14:32:45 -0700314 if (len < datalen) {
315 ALOGE("invalid PSSH data");
316 return NULL;
317 }
Marco Nelissen050eb322014-05-09 15:10:23 -0700318 // skip the data
319 data += datalen;
320 len -= datalen;
321 }
322
Marco Nelissen58344bc2014-10-23 11:36:38 -0700323 // there are <numentries> in the source buffer, we need
324 // (source buffer size) - (sizeof(uint32_t) * numentries) + sizeof(size_t)
325 // + ((sizeof(void*) + sizeof(size_t)) * numentries) bytes for the PsshInfo structure
326 // Or in other words, the data lengths in the source structure are replaced by size_t
327 // (which may be the same size or larger, for 64 bit), and in addition there is an
328 // extra pointer for each entry, and an extra size_t for the entire PsshInfo.
329 size_t newsize = buffer->size() - (sizeof(uint32_t) * numentries) + sizeof(size_t)
330 + ((sizeof(void*) + sizeof(size_t)) * numentries);
Marco Nelissen346bb512015-04-09 14:32:45 -0700331 if (newsize <= buffer->size()) {
332 ALOGE("invalid PSSH data");
333 return NULL;
334 }
Marco Nelissen050eb322014-05-09 15:10:23 -0700335 ex->mPsshBuf = new ABuffer(newsize);
336 ex->mPsshBuf->setRange(0, newsize);
337
338 // copy data
339 const uint8_t* src = buffer->data();
340 uint8_t* dst = ex->mPsshBuf->data();
Marco Nelissen58344bc2014-10-23 11:36:38 -0700341 uint8_t* dstdata = dst + sizeof(size_t) + numentries * sizeof(PsshEntry);
342 *((size_t*)dst) = numentries;
343 dst += sizeof(size_t);
Marco Nelissen050eb322014-05-09 15:10:23 -0700344 for (size_t i = 0; i < numentries; i++) {
345 // copy uuid
346 memcpy(dst, src, 16);
347 src += 16;
348 dst += 16;
349
350 // get/copy data length
351 uint32_t datalen = *((uint32_t*)src);
Marco Nelissen58344bc2014-10-23 11:36:38 -0700352 *((size_t*)dst) = datalen;
353 src += sizeof(uint32_t);
354 dst += sizeof(size_t);
Marco Nelissen050eb322014-05-09 15:10:23 -0700355
356 // the next entry in the destination is a pointer to the actual data, which we store
357 // after the array of PsshEntry
Marco Nelissen58344bc2014-10-23 11:36:38 -0700358 *((void**)dst) = dstdata;
359 dst += sizeof(void*);
Marco Nelissen050eb322014-05-09 15:10:23 -0700360
361 // copy the actual data
362 memcpy(dstdata, src, datalen);
363 dstdata += datalen;
364 src += datalen;
365 }
366
367 return (PsshInfo*) ex->mPsshBuf->data();
368}
369
Marco Nelissen3425fd52014-05-14 11:12:46 -0700370EXPORT
Marco Nelissen050eb322014-05-09 15:10:23 -0700371AMediaCodecCryptoInfo *AMediaExtractor_getSampleCryptoInfo(AMediaExtractor *ex) {
372 sp<MetaData> meta;
373 if(ex->mImpl->getSampleMeta(&meta) != 0) {
374 return NULL;
375 }
376
377 uint32_t type;
378 const void *crypteddata;
379 size_t cryptedsize;
380 if (!meta->findData(kKeyEncryptedSizes, &type, &crypteddata, &cryptedsize)) {
381 return NULL;
382 }
383 size_t numSubSamples = cryptedsize / sizeof(size_t);
384
385 const void *cleardata;
386 size_t clearsize;
387 if (meta->findData(kKeyPlainSizes, &type, &cleardata, &clearsize)) {
388 if (clearsize != cryptedsize) {
389 // The two must be of the same length.
390 return NULL;
391 }
392 }
393
394 const void *key;
395 size_t keysize;
Edwin Wongb2fb3c92016-08-29 14:57:47 -0700396 if (meta->findData(kKeyCryptoKey, &type, &key, &keysize)) {
Marco Nelissen050eb322014-05-09 15:10:23 -0700397 if (keysize != 16) {
Edwin Wongb2fb3c92016-08-29 14:57:47 -0700398 // Keys must be 16 bytes in length.
Marco Nelissen050eb322014-05-09 15:10:23 -0700399 return NULL;
400 }
401 }
402
403 const void *iv;
404 size_t ivsize;
405 if (meta->findData(kKeyCryptoIV, &type, &iv, &ivsize)) {
406 if (ivsize != 16) {
407 // IVs must be 16 bytes in length.
408 return NULL;
409 }
410 }
411
412 int32_t mode;
413 if (!meta->findInt32(kKeyCryptoMode, &mode)) {
414 mode = CryptoPlugin::kMode_AES_CTR;
415 }
416
417 return AMediaCodecCryptoInfo_new(
418 numSubSamples,
419 (uint8_t*) key,
420 (uint8_t*) iv,
Marco Nelissen79e2b622014-05-16 08:07:28 -0700421 (cryptoinfo_mode_t) mode,
Marco Nelissen050eb322014-05-09 15:10:23 -0700422 (size_t*) cleardata,
423 (size_t*) crypteddata);
424}
425
Robert Shih30e3c7d2018-01-21 17:06:12 -0800426EXPORT
427int64_t AMediaExtractor_getCachedDuration(AMediaExtractor *ex) {
428 bool eos;
429 int64_t durationUs;
430 if (ex->mImpl->getCachedDuration(&durationUs, &eos)) {
431 return durationUs;
432 }
433 return -1;
434}
Marco Nelissen0c3be872014-05-01 10:14:44 -0700435
Robert Shihd83d4f42018-02-24 19:02:46 -0800436EXPORT
437media_status_t AMediaExtractor_getSampleFormat(AMediaExtractor *ex, AMediaFormat *fmt) {
438 if (fmt == NULL) {
439 return AMEDIA_ERROR_INVALID_PARAMETER;
440 }
441
442 sp<MetaData> sampleMeta;
443 status_t err = ex->mImpl->getSampleMeta(&sampleMeta);
444 if (err != OK) {
445 return translate_error(err);
446 }
447
448 sp<AMessage> meta;
449 AMediaFormat_getFormat(fmt, &meta);
450 meta->clear();
451
452 int32_t layerId;
453 if (sampleMeta->findInt32(kKeyTemporalLayerId, &layerId)) {
454 meta->setInt32(AMEDIAFORMAT_KEY_TEMPORAL_LAYER_ID, layerId);
455 }
456
457 size_t trackIndex;
458 err = ex->mImpl->getSampleTrackIndex(&trackIndex);
459 if (err == OK) {
460 meta->setInt32(AMEDIAFORMAT_KEY_TRACK_INDEX, trackIndex);
461 sp<AMessage> trackFormat;
462 AString mime;
463 err = ex->mImpl->getTrackFormat(trackIndex, &trackFormat);
464 if (err == OK
465 && trackFormat != NULL
466 && trackFormat->findString(AMEDIAFORMAT_KEY_MIME, &mime)) {
467 meta->setString(AMEDIAFORMAT_KEY_MIME, mime);
468 }
469 }
470
471 int64_t durationUs;
472 if (sampleMeta->findInt64(kKeyDuration, &durationUs)) {
473 meta->setInt64(AMEDIAFORMAT_KEY_DURATION, durationUs);
474 }
475
476 uint32_t dataType; // unused
477 const void *seiData;
478 size_t seiLength;
479 if (sampleMeta->findData(kKeySEI, &dataType, &seiData, &seiLength)) {
480 sp<ABuffer> sei = ABuffer::CreateAsCopy(seiData, seiLength);;
481 meta->setBuffer(AMEDIAFORMAT_KEY_SEI, sei);
482 }
483
484 const void *mpegUserDataPointer;
485 size_t mpegUserDataLength;
486 if (sampleMeta->findData(
487 kKeyMpegUserData, &dataType, &mpegUserDataPointer, &mpegUserDataLength)) {
488 sp<ABuffer> mpegUserData = ABuffer::CreateAsCopy(mpegUserDataPointer, mpegUserDataLength);
489 meta->setBuffer(AMEDIAFORMAT_KEY_MPEG_USER_DATA, mpegUserData);
490 }
491
492 return AMEDIA_OK;
493}
494
Robert Shih08eb9082018-03-09 13:57:26 -0800495EXPORT
496media_status_t AMediaExtractor_disconnect(AMediaExtractor * ex) {
497 ex->mImpl->disconnect();
498 return AMEDIA_OK;
499}
500
Marco Nelissen0c3be872014-05-01 10:14:44 -0700501} // extern "C"
502