blob: aa78740215313c5d3da5fcfde9c4d71d610b269d [file] [log] [blame]
Marco Nelissen08aaabe2014-05-06 16:08:19 -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
17#define LOG_NDEBUG 0
18#define LOG_TAG "NdkMediaMuxer"
19
20
21#include "NdkMediaMuxer.h"
22#include "NdkMediaCodec.h"
23#include "NdkMediaFormatPriv.h"
24
25
26#include <utils/Log.h>
27#include <utils/StrongPointer.h>
28#include <media/stagefright/foundation/ABuffer.h>
29#include <media/stagefright/foundation/AMessage.h>
30#include <media/stagefright/MetaData.h>
31#include <media/stagefright/MediaMuxer.h>
32#include <media/IMediaHTTPService.h>
33#include <android_runtime/AndroidRuntime.h>
34#include <android_util_Binder.h>
35
36#include <jni.h>
37
38using namespace android;
39
40static int translate_error(status_t err) {
41 if (err == OK) {
42 return OK;
43 }
44 ALOGE("sf error code: %d", err);
45 return -1000;
46}
47
48struct AMediaMuxer {
49 sp<MediaMuxer> mImpl;
50
51};
52
53extern "C" {
54
Marco Nelissen3425fd52014-05-14 11:12:46 -070055EXPORT
Marco Nelissen08aaabe2014-05-06 16:08:19 -070056AMediaMuxer* AMediaMuxer_new(int fd, OutputFormat format) {
57 ALOGV("ctor");
58 AMediaMuxer *mData = new AMediaMuxer();
59 mData->mImpl = new MediaMuxer(fd, (android::MediaMuxer::OutputFormat)format);
60 return mData;
61}
62
Marco Nelissen3425fd52014-05-14 11:12:46 -070063EXPORT
Marco Nelissen08aaabe2014-05-06 16:08:19 -070064int AMediaMuxer_delete(AMediaMuxer *muxer) {
65 ALOGV("dtor");
66 delete muxer;
67 return OK;
68}
69
Marco Nelissen3425fd52014-05-14 11:12:46 -070070EXPORT
Marco Nelissen08aaabe2014-05-06 16:08:19 -070071int AMediaMuxer_setLocation(AMediaMuxer *muxer, float latitude, float longtitude) {
72 return translate_error(muxer->mImpl->setLocation(latitude * 10000, longtitude * 10000));
73}
74
Marco Nelissen3425fd52014-05-14 11:12:46 -070075EXPORT
Marco Nelissen08aaabe2014-05-06 16:08:19 -070076int AMediaMuxer_setOrientationHint(AMediaMuxer *muxer, int degrees) {
77 return translate_error(muxer->mImpl->setOrientationHint(degrees));
78}
79
Marco Nelissen3425fd52014-05-14 11:12:46 -070080EXPORT
Marco Nelissen08aaabe2014-05-06 16:08:19 -070081ssize_t AMediaMuxer_addTrack(AMediaMuxer *muxer, const AMediaFormat *format) {
82 sp<AMessage> msg;
83 AMediaFormat_getFormat(format, &msg);
84 return translate_error(muxer->mImpl->addTrack(msg));
85}
86
Marco Nelissen3425fd52014-05-14 11:12:46 -070087EXPORT
Marco Nelissen08aaabe2014-05-06 16:08:19 -070088int AMediaMuxer_start(AMediaMuxer *muxer) {
89 return translate_error(muxer->mImpl->start());
90}
91
Marco Nelissen3425fd52014-05-14 11:12:46 -070092EXPORT
Marco Nelissen08aaabe2014-05-06 16:08:19 -070093int AMediaMuxer_stop(AMediaMuxer *muxer) {
94 return translate_error(muxer->mImpl->stop());
95}
96
Marco Nelissen3425fd52014-05-14 11:12:46 -070097EXPORT
Marco Nelissen08aaabe2014-05-06 16:08:19 -070098int AMediaMuxer_writeSampleData(AMediaMuxer *muxer,
99 size_t trackIdx, const uint8_t *data, const AMediaCodecBufferInfo &info) {
100 sp<ABuffer> buf = new ABuffer((void*)(data + info.offset), info.size);
101 return translate_error(
102 muxer->mImpl->writeSampleData(buf, trackIdx, info.presentationTimeUs, info.flags));
103}
104
105
106} // extern "C"
107