Merge change Iea6a38c6 into eclair-mr2
* changes: Squashed commit of the following:
This commit is contained in:
59
include/media/MediaRecorderBase.h
Normal file
59
include/media/MediaRecorderBase.h
Normal file
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (C) 2009 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef MEDIA_RECORDER_BASE_H_
|
||||
|
||||
#define MEDIA_RECORDER_BASE_H_
|
||||
|
||||
#include <media/mediarecorder.h>
|
||||
|
||||
namespace android {
|
||||
|
||||
class ISurface;
|
||||
|
||||
struct MediaRecorderBase {
|
||||
MediaRecorderBase() {}
|
||||
virtual ~MediaRecorderBase() {}
|
||||
|
||||
virtual status_t init() = 0;
|
||||
virtual status_t setAudioSource(audio_source as) = 0;
|
||||
virtual status_t setVideoSource(video_source vs) = 0;
|
||||
virtual status_t setOutputFormat(output_format of) = 0;
|
||||
virtual status_t setAudioEncoder(audio_encoder ae) = 0;
|
||||
virtual status_t setVideoEncoder(video_encoder ve) = 0;
|
||||
virtual status_t setVideoSize(int width, int height) = 0;
|
||||
virtual status_t setVideoFrameRate(int frames_per_second) = 0;
|
||||
virtual status_t setCamera(const sp<ICamera>& camera) = 0;
|
||||
virtual status_t setPreviewSurface(const sp<ISurface>& surface) = 0;
|
||||
virtual status_t setOutputFile(const char *path) = 0;
|
||||
virtual status_t setOutputFile(int fd, int64_t offset, int64_t length) = 0;
|
||||
virtual status_t setParameters(const String8& params) = 0;
|
||||
virtual status_t setListener(const sp<IMediaPlayerClient>& listener) = 0;
|
||||
virtual status_t prepare() = 0;
|
||||
virtual status_t start() = 0;
|
||||
virtual status_t stop() = 0;
|
||||
virtual status_t close() = 0;
|
||||
virtual status_t reset() = 0;
|
||||
virtual status_t getMaxAmplitude(int *max) = 0;
|
||||
|
||||
private:
|
||||
MediaRecorderBase(const MediaRecorderBase &);
|
||||
MediaRecorderBase &operator=(const MediaRecorderBase &);
|
||||
};
|
||||
|
||||
} // namespace android
|
||||
|
||||
#endif // MEDIA_RECORDER_BASE_H_
|
||||
@@ -18,8 +18,8 @@
|
||||
#ifndef ANDROID_PVMEDIARECORDER_H
|
||||
#define ANDROID_PVMEDIARECORDER_H
|
||||
|
||||
#include <media/mediarecorder.h>
|
||||
#include <media/IMediaPlayerClient.h>
|
||||
#include <media/MediaRecorderBase.h>
|
||||
|
||||
namespace android {
|
||||
|
||||
@@ -27,37 +27,39 @@ class ISurface;
|
||||
class ICamera;
|
||||
class AuthorDriverWrapper;
|
||||
|
||||
class PVMediaRecorder
|
||||
{
|
||||
class PVMediaRecorder : public MediaRecorderBase {
|
||||
public:
|
||||
PVMediaRecorder();
|
||||
~PVMediaRecorder();
|
||||
virtual ~PVMediaRecorder();
|
||||
|
||||
status_t init();
|
||||
status_t setAudioSource(audio_source as);
|
||||
status_t setVideoSource(video_source vs);
|
||||
status_t setOutputFormat(output_format of);
|
||||
status_t setAudioEncoder(audio_encoder ae);
|
||||
status_t setVideoEncoder(video_encoder ve);
|
||||
status_t setVideoSize(int width, int height);
|
||||
status_t setVideoFrameRate(int frames_per_second);
|
||||
status_t setCamera(const sp<ICamera>& camera);
|
||||
status_t setPreviewSurface(const sp<ISurface>& surface);
|
||||
status_t setOutputFile(const char *path);
|
||||
status_t setOutputFile(int fd, int64_t offset, int64_t length);
|
||||
status_t setParameters(const String8& params);
|
||||
status_t setListener(const sp<IMediaPlayerClient>& listener);
|
||||
status_t prepare();
|
||||
status_t start();
|
||||
status_t stop();
|
||||
status_t close();
|
||||
status_t reset();
|
||||
status_t getMaxAmplitude(int *max);
|
||||
virtual status_t init();
|
||||
virtual status_t setAudioSource(audio_source as);
|
||||
virtual status_t setVideoSource(video_source vs);
|
||||
virtual status_t setOutputFormat(output_format of);
|
||||
virtual status_t setAudioEncoder(audio_encoder ae);
|
||||
virtual status_t setVideoEncoder(video_encoder ve);
|
||||
virtual status_t setVideoSize(int width, int height);
|
||||
virtual status_t setVideoFrameRate(int frames_per_second);
|
||||
virtual status_t setCamera(const sp<ICamera>& camera);
|
||||
virtual status_t setPreviewSurface(const sp<ISurface>& surface);
|
||||
virtual status_t setOutputFile(const char *path);
|
||||
virtual status_t setOutputFile(int fd, int64_t offset, int64_t length);
|
||||
virtual status_t setParameters(const String8& params);
|
||||
virtual status_t setListener(const sp<IMediaPlayerClient>& listener);
|
||||
virtual status_t prepare();
|
||||
virtual status_t start();
|
||||
virtual status_t stop();
|
||||
virtual status_t close();
|
||||
virtual status_t reset();
|
||||
virtual status_t getMaxAmplitude(int *max);
|
||||
|
||||
private:
|
||||
status_t doStop();
|
||||
|
||||
AuthorDriverWrapper* mAuthorDriverWrapper;
|
||||
|
||||
PVMediaRecorder(const PVMediaRecorder &);
|
||||
PVMediaRecorder &operator=(const PVMediaRecorder &);
|
||||
};
|
||||
|
||||
}; // namespace android
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
|
||||
namespace android {
|
||||
|
||||
class ICamera;
|
||||
class IMemory;
|
||||
class ISurface;
|
||||
class Camera;
|
||||
@@ -33,9 +34,12 @@ class Camera;
|
||||
class CameraSource : public MediaSource {
|
||||
public:
|
||||
static CameraSource *Create();
|
||||
static CameraSource *CreateFromICamera(const sp<ICamera> &icamera);
|
||||
|
||||
virtual ~CameraSource();
|
||||
|
||||
void setPreviewSurface(const sp<ISurface> &surface);
|
||||
|
||||
virtual status_t start(MetaData *params = NULL);
|
||||
virtual status_t stop();
|
||||
|
||||
@@ -48,6 +52,7 @@ private:
|
||||
friend class CameraSourceListener;
|
||||
|
||||
sp<Camera> mCamera;
|
||||
sp<ISurface> mPreviewSurface;
|
||||
|
||||
Mutex mLock;
|
||||
Condition mFrameAvailableCondition;
|
||||
|
||||
@@ -33,6 +33,7 @@ class MetaData;
|
||||
class MPEG4Writer : public RefBase {
|
||||
public:
|
||||
MPEG4Writer(const char *filename);
|
||||
MPEG4Writer(int fd);
|
||||
|
||||
void addSource(const sp<MediaSource> &source);
|
||||
status_t start();
|
||||
@@ -65,6 +66,7 @@ private:
|
||||
List<off_t> mBoxes;
|
||||
|
||||
off_t addSample(MediaBuffer *buffer);
|
||||
off_t addLengthPrefixedSample(MediaBuffer *buffer);
|
||||
|
||||
MPEG4Writer(const MPEG4Writer &);
|
||||
MPEG4Writer &operator=(const MPEG4Writer &);
|
||||
|
||||
@@ -38,7 +38,8 @@ enum {
|
||||
kKeyESDS = 'esds', // raw data
|
||||
kKeyAVCC = 'avcc', // raw data
|
||||
kKeyWantsNALFragments = 'NALf',
|
||||
kKeyIsSyncFrame = 'sync',
|
||||
kKeyIsSyncFrame = 'sync', // int32_t (bool)
|
||||
kKeyIsCodecConfig = 'conf', // int32_t (bool)
|
||||
kKeyTime = 'time', // int64_t (usecs)
|
||||
kKeyDuration = 'dura', // int64_t (usecs)
|
||||
kKeyColorFormat = 'colf',
|
||||
|
||||
@@ -159,6 +159,7 @@ private:
|
||||
const char *mime, OMX_U32 width, OMX_U32 height);
|
||||
|
||||
status_t setupMPEG4EncoderParameters();
|
||||
status_t setupAVCEncoderParameters();
|
||||
|
||||
void setVideoOutputFormat(
|
||||
const char *mime, OMX_U32 width, OMX_U32 height);
|
||||
|
||||
@@ -19,8 +19,9 @@ LOCAL_SRC_FILES:= \
|
||||
ifeq ($(BUILD_WITH_FULL_STAGEFRIGHT),true)
|
||||
|
||||
LOCAL_SRC_FILES += \
|
||||
StagefrightMetadataRetriever.cpp \
|
||||
StagefrightPlayer.cpp \
|
||||
StagefrightMetadataRetriever.cpp
|
||||
StagefrightRecorder.cpp
|
||||
|
||||
LOCAL_CFLAGS += -DBUILD_WITH_FULL_STAGEFRIGHT=1
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <cutils/atomic.h>
|
||||
#include <cutils/properties.h> // for property_get
|
||||
#include <android_runtime/ActivityManager.h>
|
||||
#include <binder/IPCThreadState.h>
|
||||
#include <binder/IServiceManager.h>
|
||||
@@ -37,6 +38,8 @@
|
||||
#include "MediaRecorderClient.h"
|
||||
#include "MediaPlayerService.h"
|
||||
|
||||
#include "StagefrightRecorder.h"
|
||||
|
||||
namespace android {
|
||||
|
||||
const char* cameraPermission = "android.permission.CAMERA";
|
||||
@@ -286,7 +289,18 @@ MediaRecorderClient::MediaRecorderClient(const sp<MediaPlayerService>& service,
|
||||
{
|
||||
LOGV("Client constructor");
|
||||
mPid = pid;
|
||||
mRecorder = new PVMediaRecorder();
|
||||
|
||||
#if BUILD_WITH_FULL_STAGEFRIGHT
|
||||
char value[PROPERTY_VALUE_MAX];
|
||||
if (property_get("media.stagefright.enable-record", value, NULL)
|
||||
&& (!strcmp(value, "1") || !strcasecmp(value, "true"))) {
|
||||
mRecorder = new StagefrightRecorder;
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
mRecorder = new PVMediaRecorder();
|
||||
}
|
||||
|
||||
mMediaPlayerService = service;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,8 +22,7 @@
|
||||
|
||||
namespace android {
|
||||
|
||||
class PVMediaRecorder;
|
||||
class ISurface;
|
||||
class MediaRecorderBase;
|
||||
class MediaPlayerService;
|
||||
|
||||
class MediaRecorderClient : public BnMediaRecorder
|
||||
@@ -59,7 +58,7 @@ private:
|
||||
|
||||
pid_t mPid;
|
||||
Mutex mLock;
|
||||
PVMediaRecorder *mRecorder;
|
||||
MediaRecorderBase *mRecorder;
|
||||
sp<MediaPlayerService> mMediaPlayerService;
|
||||
};
|
||||
|
||||
|
||||
241
media/libmediaplayerservice/StagefrightRecorder.cpp
Normal file
241
media/libmediaplayerservice/StagefrightRecorder.cpp
Normal file
@@ -0,0 +1,241 @@
|
||||
/*
|
||||
* Copyright (C) 2009 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
//#define LOG_NDEBUG 0
|
||||
#define LOG_TAG "StagefrightRecorder"
|
||||
#include <utils/Log.h>
|
||||
|
||||
#include "StagefrightRecorder.h"
|
||||
|
||||
#include <media/stagefright/CameraSource.h>
|
||||
#include <media/stagefright/MPEG4Writer.h>
|
||||
#include <media/stagefright/MediaDebug.h>
|
||||
#include <media/stagefright/MediaDefs.h>
|
||||
#include <media/stagefright/MetaData.h>
|
||||
#include <media/stagefright/OMXClient.h>
|
||||
#include <media/stagefright/OMXCodec.h>
|
||||
#include <ui/ICamera.h>
|
||||
#include <ui/ISurface.h>
|
||||
#include <utils/Errors.h>
|
||||
|
||||
namespace android {
|
||||
|
||||
StagefrightRecorder::StagefrightRecorder() {
|
||||
reset();
|
||||
}
|
||||
|
||||
StagefrightRecorder::~StagefrightRecorder() {
|
||||
stop();
|
||||
|
||||
if (mOutputFd >= 0) {
|
||||
::close(mOutputFd);
|
||||
mOutputFd = -1;
|
||||
}
|
||||
}
|
||||
|
||||
status_t StagefrightRecorder::init() {
|
||||
return OK;
|
||||
}
|
||||
|
||||
status_t StagefrightRecorder::setAudioSource(audio_source as) {
|
||||
mAudioSource = as;
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
status_t StagefrightRecorder::setVideoSource(video_source vs) {
|
||||
mVideoSource = vs;
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
status_t StagefrightRecorder::setOutputFormat(output_format of) {
|
||||
mOutputFormat = of;
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
status_t StagefrightRecorder::setAudioEncoder(audio_encoder ae) {
|
||||
mAudioEncoder = ae;
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
status_t StagefrightRecorder::setVideoEncoder(video_encoder ve) {
|
||||
mVideoEncoder = ve;
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
status_t StagefrightRecorder::setVideoSize(int width, int height) {
|
||||
mVideoWidth = width;
|
||||
mVideoHeight = height;
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
status_t StagefrightRecorder::setVideoFrameRate(int frames_per_second) {
|
||||
mFrameRate = frames_per_second;
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
status_t StagefrightRecorder::setCamera(const sp<ICamera> &camera) {
|
||||
mCamera = camera;
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
status_t StagefrightRecorder::setPreviewSurface(const sp<ISurface> &surface) {
|
||||
mPreviewSurface = surface;
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
status_t StagefrightRecorder::setOutputFile(const char *path) {
|
||||
// We don't actually support this at all, as the media_server process
|
||||
// no longer has permissions to create files.
|
||||
|
||||
return UNKNOWN_ERROR;
|
||||
}
|
||||
|
||||
status_t StagefrightRecorder::setOutputFile(int fd, int64_t offset, int64_t length) {
|
||||
// These don't make any sense, do they?
|
||||
CHECK_EQ(offset, 0);
|
||||
CHECK_EQ(length, 0);
|
||||
|
||||
if (mOutputFd >= 0) {
|
||||
::close(mOutputFd);
|
||||
}
|
||||
mOutputFd = dup(fd);
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
status_t StagefrightRecorder::setParameters(const String8 ¶ms) {
|
||||
mParams = params;
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
status_t StagefrightRecorder::setListener(const sp<IMediaPlayerClient> &listener) {
|
||||
mListener = listener;
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
status_t StagefrightRecorder::prepare() {
|
||||
return OK;
|
||||
}
|
||||
|
||||
status_t StagefrightRecorder::start() {
|
||||
if (mWriter != NULL) {
|
||||
return UNKNOWN_ERROR;
|
||||
}
|
||||
|
||||
if (mVideoSource == VIDEO_SOURCE_CAMERA) {
|
||||
CHECK(mCamera != NULL);
|
||||
|
||||
sp<CameraSource> cameraSource =
|
||||
CameraSource::CreateFromICamera(mCamera);
|
||||
|
||||
CHECK(cameraSource != NULL);
|
||||
|
||||
cameraSource->setPreviewSurface(mPreviewSurface);
|
||||
|
||||
sp<MetaData> enc_meta = new MetaData;
|
||||
switch (mVideoEncoder) {
|
||||
case VIDEO_ENCODER_H263:
|
||||
enc_meta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_H263);
|
||||
break;
|
||||
|
||||
case VIDEO_ENCODER_MPEG_4_SP:
|
||||
enc_meta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_MPEG4);
|
||||
break;
|
||||
|
||||
case VIDEO_ENCODER_H264:
|
||||
enc_meta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_AVC);
|
||||
break;
|
||||
|
||||
default:
|
||||
CHECK(!"Should not be here, unsupported video encoding.");
|
||||
break;
|
||||
}
|
||||
|
||||
sp<MetaData> meta = cameraSource->getFormat();
|
||||
|
||||
int32_t width, height;
|
||||
CHECK(meta->findInt32(kKeyWidth, &width));
|
||||
CHECK(meta->findInt32(kKeyHeight, &height));
|
||||
|
||||
enc_meta->setInt32(kKeyWidth, width);
|
||||
enc_meta->setInt32(kKeyHeight, height);
|
||||
|
||||
OMXClient client;
|
||||
CHECK_EQ(client.connect(), OK);
|
||||
|
||||
sp<MediaSource> encoder =
|
||||
OMXCodec::Create(
|
||||
client.interface(), enc_meta,
|
||||
true /* createEncoder */, cameraSource);
|
||||
|
||||
CHECK(mOutputFd >= 0);
|
||||
mWriter = new MPEG4Writer(dup(mOutputFd));
|
||||
mWriter->addSource(encoder);
|
||||
mWriter->start();
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
status_t StagefrightRecorder::stop() {
|
||||
if (mWriter == NULL) {
|
||||
return UNKNOWN_ERROR;
|
||||
}
|
||||
|
||||
mWriter->stop();
|
||||
mWriter = NULL;
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
status_t StagefrightRecorder::close() {
|
||||
stop();
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
status_t StagefrightRecorder::reset() {
|
||||
stop();
|
||||
|
||||
mAudioSource = AUDIO_SOURCE_LIST_END;
|
||||
mVideoSource = VIDEO_SOURCE_LIST_END;
|
||||
mOutputFormat = OUTPUT_FORMAT_LIST_END;
|
||||
mAudioEncoder = AUDIO_ENCODER_LIST_END;
|
||||
mVideoEncoder = VIDEO_ENCODER_LIST_END;
|
||||
mVideoWidth = -1;
|
||||
mVideoHeight = -1;
|
||||
mFrameRate = -1;
|
||||
mOutputFd = -1;
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
status_t StagefrightRecorder::getMaxAmplitude(int *max) {
|
||||
return UNKNOWN_ERROR;
|
||||
}
|
||||
|
||||
} // namespace android
|
||||
76
media/libmediaplayerservice/StagefrightRecorder.h
Normal file
76
media/libmediaplayerservice/StagefrightRecorder.h
Normal file
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright (C) 2009 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef STAGEFRIGHT_RECORDER_H_
|
||||
|
||||
#define STAGEFRIGHT_RECORDER_H_
|
||||
|
||||
#include <media/MediaRecorderBase.h>
|
||||
#include <utils/String8.h>
|
||||
|
||||
namespace android {
|
||||
|
||||
class MPEG4Writer;
|
||||
|
||||
struct StagefrightRecorder : public MediaRecorderBase {
|
||||
StagefrightRecorder();
|
||||
virtual ~StagefrightRecorder();
|
||||
|
||||
virtual status_t init();
|
||||
virtual status_t setAudioSource(audio_source as);
|
||||
virtual status_t setVideoSource(video_source vs);
|
||||
virtual status_t setOutputFormat(output_format of);
|
||||
virtual status_t setAudioEncoder(audio_encoder ae);
|
||||
virtual status_t setVideoEncoder(video_encoder ve);
|
||||
virtual status_t setVideoSize(int width, int height);
|
||||
virtual status_t setVideoFrameRate(int frames_per_second);
|
||||
virtual status_t setCamera(const sp<ICamera>& camera);
|
||||
virtual status_t setPreviewSurface(const sp<ISurface>& surface);
|
||||
virtual status_t setOutputFile(const char *path);
|
||||
virtual status_t setOutputFile(int fd, int64_t offset, int64_t length);
|
||||
virtual status_t setParameters(const String8& params);
|
||||
virtual status_t setListener(const sp<IMediaPlayerClient>& listener);
|
||||
virtual status_t prepare();
|
||||
virtual status_t start();
|
||||
virtual status_t stop();
|
||||
virtual status_t close();
|
||||
virtual status_t reset();
|
||||
virtual status_t getMaxAmplitude(int *max);
|
||||
|
||||
private:
|
||||
sp<ICamera> mCamera;
|
||||
sp<ISurface> mPreviewSurface;
|
||||
sp<IMediaPlayerClient> mListener;
|
||||
sp<MPEG4Writer> mWriter;
|
||||
|
||||
audio_source mAudioSource;
|
||||
video_source mVideoSource;
|
||||
output_format mOutputFormat;
|
||||
audio_encoder mAudioEncoder;
|
||||
video_encoder mVideoEncoder;
|
||||
int mVideoWidth, mVideoHeight;
|
||||
int mFrameRate;
|
||||
String8 mParams;
|
||||
int mOutputFd;
|
||||
|
||||
StagefrightRecorder(const StagefrightRecorder &);
|
||||
StagefrightRecorder &operator=(const StagefrightRecorder &);
|
||||
};
|
||||
|
||||
} // namespace android
|
||||
|
||||
#endif // STAGEFRIGHT_RECORDER_H_
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include <OMX_Component.h>
|
||||
|
||||
#include <binder/IServiceManager.h>
|
||||
#include <cutils/properties.h> // for property_get
|
||||
#include <media/stagefright/CameraSource.h>
|
||||
#include <media/stagefright/MediaDebug.h>
|
||||
#include <media/stagefright/MediaDefs.h>
|
||||
@@ -123,6 +124,17 @@ CameraSource *CameraSource::Create() {
|
||||
return new CameraSource(camera);
|
||||
}
|
||||
|
||||
// static
|
||||
CameraSource *CameraSource::CreateFromICamera(const sp<ICamera> &icamera) {
|
||||
sp<Camera> camera = Camera::create(icamera);
|
||||
|
||||
if (camera.get() == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return new CameraSource(camera);
|
||||
}
|
||||
|
||||
CameraSource::CameraSource(const sp<Camera> &camera)
|
||||
: mCamera(camera),
|
||||
mWidth(0),
|
||||
@@ -130,6 +142,13 @@ CameraSource::CameraSource(const sp<Camera> &camera)
|
||||
mFirstFrameTimeUs(0),
|
||||
mNumFrames(0),
|
||||
mStarted(false) {
|
||||
char value[PROPERTY_VALUE_MAX];
|
||||
if (property_get("ro.hardware", value, NULL) && !strcmp(value, "sholes")) {
|
||||
// The hardware encoder(s) do not support yuv420, but only YCbYCr,
|
||||
// fortunately the camera also supports this, so we needn't transcode.
|
||||
mCamera->setParameters(String8("preview-format=yuv422i-yuyv"));
|
||||
}
|
||||
|
||||
String8 s = mCamera->getParameters();
|
||||
printf("params: \"%s\"\n", s.string());
|
||||
|
||||
@@ -143,13 +162,18 @@ CameraSource::~CameraSource() {
|
||||
}
|
||||
}
|
||||
|
||||
void CameraSource::setPreviewSurface(const sp<ISurface> &surface) {
|
||||
mPreviewSurface = surface;
|
||||
}
|
||||
|
||||
status_t CameraSource::start(MetaData *) {
|
||||
CHECK(!mStarted);
|
||||
|
||||
mCamera->setListener(new CameraSourceListener(this));
|
||||
|
||||
sp<ISurface> dummy = new DummySurface;
|
||||
status_t err = mCamera->setPreviewDisplay(dummy);
|
||||
status_t err =
|
||||
mCamera->setPreviewDisplay(
|
||||
mPreviewSurface != NULL ? mPreviewSurface : new DummySurface);
|
||||
CHECK_EQ(err, OK);
|
||||
|
||||
mCamera->setPreviewCallbackFlags(
|
||||
|
||||
@@ -75,6 +75,13 @@ MPEG4Writer::MPEG4Writer(const char *filename)
|
||||
CHECK(mFile != NULL);
|
||||
}
|
||||
|
||||
MPEG4Writer::MPEG4Writer(int fd)
|
||||
: mFile(fdopen(fd, "wb")),
|
||||
mOffset(0),
|
||||
mMdatOffset(0) {
|
||||
CHECK(mFile != NULL);
|
||||
}
|
||||
|
||||
MPEG4Writer::~MPEG4Writer() {
|
||||
stop();
|
||||
|
||||
@@ -203,6 +210,27 @@ off_t MPEG4Writer::addSample(MediaBuffer *buffer) {
|
||||
return old_offset;
|
||||
}
|
||||
|
||||
off_t MPEG4Writer::addLengthPrefixedSample(MediaBuffer *buffer) {
|
||||
Mutex::Autolock autoLock(mLock);
|
||||
|
||||
off_t old_offset = mOffset;
|
||||
|
||||
size_t length = buffer->range_length();
|
||||
CHECK(length < 65536);
|
||||
|
||||
uint8_t x = length >> 8;
|
||||
fwrite(&x, 1, 1, mFile);
|
||||
x = length & 0xff;
|
||||
fwrite(&x, 1, 1, mFile);
|
||||
|
||||
fwrite((const uint8_t *)buffer->data() + buffer->range_offset(),
|
||||
1, length, mFile);
|
||||
|
||||
mOffset += length + 2;
|
||||
|
||||
return old_offset;
|
||||
}
|
||||
|
||||
void MPEG4Writer::beginBox(const char *fourcc) {
|
||||
CHECK_EQ(strlen(fourcc), 4);
|
||||
|
||||
@@ -348,11 +376,12 @@ void *MPEG4Writer::Track::ThreadWrapper(void *me) {
|
||||
}
|
||||
|
||||
void MPEG4Writer::Track::threadEntry() {
|
||||
bool is_mpeg4 = false;
|
||||
sp<MetaData> meta = mSource->getFormat();
|
||||
const char *mime;
|
||||
meta->findCString(kKeyMIMEType, &mime);
|
||||
is_mpeg4 = !strcasecmp(mime, MEDIA_MIMETYPE_VIDEO_MPEG4);
|
||||
bool is_mpeg4 = !strcasecmp(mime, MEDIA_MIMETYPE_VIDEO_MPEG4);
|
||||
bool is_avc = !strcasecmp(mime, MEDIA_MIMETYPE_VIDEO_AVC);
|
||||
int32_t count = 0;
|
||||
|
||||
MediaBuffer *buffer;
|
||||
while (!mDone && mSource->read(&buffer) == OK) {
|
||||
@@ -363,6 +392,55 @@ void MPEG4Writer::Track::threadEntry() {
|
||||
continue;
|
||||
}
|
||||
|
||||
++count;
|
||||
|
||||
if (is_avc && count < 3) {
|
||||
size_t size = buffer->range_length();
|
||||
|
||||
switch (count) {
|
||||
case 1:
|
||||
{
|
||||
CHECK_EQ(mCodecSpecificData, NULL);
|
||||
mCodecSpecificData = malloc(size + 8);
|
||||
uint8_t *header = (uint8_t *)mCodecSpecificData;
|
||||
header[0] = 1;
|
||||
header[1] = 0x42; // profile
|
||||
header[2] = 0x80;
|
||||
header[3] = 0x1e; // level
|
||||
header[4] = 0xfc | 3;
|
||||
header[5] = 0xe0 | 1;
|
||||
header[6] = size >> 8;
|
||||
header[7] = size & 0xff;
|
||||
memcpy(&header[8],
|
||||
(const uint8_t *)buffer->data() + buffer->range_offset(),
|
||||
size);
|
||||
|
||||
mCodecSpecificDataSize = size + 8;
|
||||
break;
|
||||
}
|
||||
|
||||
case 2:
|
||||
{
|
||||
size_t offset = mCodecSpecificDataSize;
|
||||
mCodecSpecificDataSize += size + 3;
|
||||
mCodecSpecificData = realloc(mCodecSpecificData, mCodecSpecificDataSize);
|
||||
uint8_t *header = (uint8_t *)mCodecSpecificData;
|
||||
header[offset] = 1;
|
||||
header[offset + 1] = size >> 8;
|
||||
header[offset + 2] = size & 0xff;
|
||||
memcpy(&header[offset + 3],
|
||||
(const uint8_t *)buffer->data() + buffer->range_offset(),
|
||||
size);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
buffer->release();
|
||||
buffer = NULL;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (mCodecSpecificData == NULL && is_mpeg4) {
|
||||
const uint8_t *data =
|
||||
(const uint8_t *)buffer->data() + buffer->range_offset();
|
||||
@@ -393,10 +471,11 @@ void MPEG4Writer::Track::threadEntry() {
|
||||
buffer->set_range(buffer->range_offset() + offset, size - offset);
|
||||
}
|
||||
|
||||
off_t offset = mOwner->addSample(buffer);
|
||||
off_t offset = is_avc ? mOwner->addLengthPrefixedSample(buffer)
|
||||
: mOwner->addSample(buffer);
|
||||
|
||||
SampleInfo info;
|
||||
info.size = buffer->range_length();
|
||||
info.size = is_avc ? buffer->range_length() + 2 : buffer->range_length();
|
||||
info.offset = offset;
|
||||
|
||||
int64_t timestampUs;
|
||||
@@ -556,6 +635,8 @@ void MPEG4Writer::Track::writeTrackHeader(int32_t trackID) {
|
||||
mOwner->beginBox("mp4v");
|
||||
} else if (!strcasecmp(MEDIA_MIMETYPE_VIDEO_H263, mime)) {
|
||||
mOwner->beginBox("s263");
|
||||
} else if (!strcasecmp(MEDIA_MIMETYPE_VIDEO_AVC, mime)) {
|
||||
mOwner->beginBox("avc1");
|
||||
} else {
|
||||
LOGE("Unknown mime type '%s'.", mime);
|
||||
CHECK(!"should not be here, unknown mime type.");
|
||||
@@ -631,8 +712,13 @@ void MPEG4Writer::Track::writeTrackHeader(int32_t trackID) {
|
||||
mOwner->writeInt8(0); // profile: 0
|
||||
|
||||
mOwner->endBox(); // d263
|
||||
} else if (!strcasecmp(MEDIA_MIMETYPE_VIDEO_AVC, mime)) {
|
||||
mOwner->beginBox("avcC");
|
||||
mOwner->write(mCodecSpecificData, mCodecSpecificDataSize);
|
||||
mOwner->endBox(); // avcC
|
||||
}
|
||||
mOwner->endBox(); // mp4v or s263
|
||||
|
||||
mOwner->endBox(); // mp4v, s263 or avc1
|
||||
}
|
||||
mOwner->endBox(); // stsd
|
||||
|
||||
|
||||
@@ -594,11 +594,9 @@ void OMXCodec::setVideoInputFormat(
|
||||
CHECK(!"Should not be here. Not a supported video mime type.");
|
||||
}
|
||||
|
||||
OMX_COLOR_FORMATTYPE colorFormat =
|
||||
0 ? OMX_COLOR_FormatYCbYCr : OMX_COLOR_FormatCbYCrY;
|
||||
|
||||
if (!strncmp("OMX.qcom.video.encoder.", mComponentName, 23)) {
|
||||
colorFormat = OMX_COLOR_FormatYUV420SemiPlanar;
|
||||
OMX_COLOR_FORMATTYPE colorFormat = OMX_COLOR_FormatYUV420SemiPlanar;
|
||||
if (!strcasecmp("OMX.TI.Video.encoder", mComponentName)) {
|
||||
colorFormat = OMX_COLOR_FormatYCbYCr;
|
||||
}
|
||||
|
||||
CHECK_EQ(setVideoPortFormatType(
|
||||
@@ -666,6 +664,12 @@ void OMXCodec::setVideoInputFormat(
|
||||
case OMX_VIDEO_CodingH263:
|
||||
break;
|
||||
|
||||
case OMX_VIDEO_CodingAVC:
|
||||
{
|
||||
CHECK_EQ(setupAVCEncoderParameters(), OK);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
CHECK(!"Support for this compressionFormat to be implemented.");
|
||||
break;
|
||||
@@ -749,6 +753,64 @@ status_t OMXCodec::setupMPEG4EncoderParameters() {
|
||||
return OK;
|
||||
}
|
||||
|
||||
status_t OMXCodec::setupAVCEncoderParameters() {
|
||||
OMX_VIDEO_PARAM_AVCTYPE h264type;
|
||||
InitOMXParams(&h264type);
|
||||
h264type.nPortIndex = kPortIndexOutput;
|
||||
|
||||
status_t err = mOMX->getParameter(
|
||||
mNode, OMX_IndexParamVideoAvc, &h264type, sizeof(h264type));
|
||||
CHECK_EQ(err, OK);
|
||||
|
||||
h264type.nAllowedPictureTypes =
|
||||
OMX_VIDEO_PictureTypeI | OMX_VIDEO_PictureTypeP;
|
||||
|
||||
h264type.nSliceHeaderSpacing = 0;
|
||||
h264type.nBFrames = 0;
|
||||
h264type.bUseHadamard = OMX_TRUE;
|
||||
h264type.nRefFrames = 1;
|
||||
h264type.nRefIdx10ActiveMinus1 = 0;
|
||||
h264type.nRefIdx11ActiveMinus1 = 0;
|
||||
h264type.bEnableUEP = OMX_FALSE;
|
||||
h264type.bEnableFMO = OMX_FALSE;
|
||||
h264type.bEnableASO = OMX_FALSE;
|
||||
h264type.bEnableRS = OMX_FALSE;
|
||||
h264type.eProfile = OMX_VIDEO_AVCProfileBaseline;
|
||||
h264type.eLevel = OMX_VIDEO_AVCLevel1b;
|
||||
h264type.bFrameMBsOnly = OMX_TRUE;
|
||||
h264type.bMBAFF = OMX_FALSE;
|
||||
h264type.bEntropyCodingCABAC = OMX_FALSE;
|
||||
h264type.bWeightedPPrediction = OMX_FALSE;
|
||||
h264type.bconstIpred = OMX_FALSE;
|
||||
h264type.bDirect8x8Inference = OMX_FALSE;
|
||||
h264type.bDirectSpatialTemporal = OMX_FALSE;
|
||||
h264type.nCabacInitIdc = 0;
|
||||
h264type.eLoopFilterMode = OMX_VIDEO_AVCLoopFilterEnable;
|
||||
|
||||
err = mOMX->setParameter(
|
||||
mNode, OMX_IndexParamVideoAvc, &h264type, sizeof(h264type));
|
||||
CHECK_EQ(err, OK);
|
||||
|
||||
OMX_VIDEO_PARAM_BITRATETYPE bitrateType;
|
||||
InitOMXParams(&bitrateType);
|
||||
bitrateType.nPortIndex = kPortIndexOutput;
|
||||
|
||||
err = mOMX->getParameter(
|
||||
mNode, OMX_IndexParamVideoBitrate,
|
||||
&bitrateType, sizeof(bitrateType));
|
||||
CHECK_EQ(err, OK);
|
||||
|
||||
bitrateType.eControlRate = OMX_Video_ControlRateVariable;
|
||||
bitrateType.nTargetBitrate = 1000000;
|
||||
|
||||
err = mOMX->setParameter(
|
||||
mNode, OMX_IndexParamVideoBitrate,
|
||||
&bitrateType, sizeof(bitrateType));
|
||||
CHECK_EQ(err, OK);
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
void OMXCodec::setVideoOutputFormat(
|
||||
const char *mime, OMX_U32 width, OMX_U32 height) {
|
||||
CODEC_LOGV("setVideoOutputFormat width=%ld, height=%ld", width, height);
|
||||
@@ -849,7 +911,6 @@ void OMXCodec::setVideoOutputFormat(
|
||||
CHECK_EQ(err, OK);
|
||||
}
|
||||
|
||||
|
||||
OMXCodec::OMXCodec(
|
||||
const sp<IOMX> &omx, IOMX::node_id node, uint32_t quirks,
|
||||
bool isEncoder,
|
||||
@@ -1178,6 +1239,9 @@ void OMXCodec::on_message(const omx_message &msg) {
|
||||
if (msg.u.extended_buffer_data.flags & OMX_BUFFERFLAG_SYNCFRAME) {
|
||||
buffer->meta_data()->setInt32(kKeyIsSyncFrame, true);
|
||||
}
|
||||
if (msg.u.extended_buffer_data.flags & OMX_BUFFERFLAG_CODECCONFIG) {
|
||||
buffer->meta_data()->setInt32(kKeyIsCodecConfig, true);
|
||||
}
|
||||
|
||||
buffer->meta_data()->setPointer(
|
||||
kKeyPlatformPrivate,
|
||||
@@ -1738,6 +1802,13 @@ void OMXCodec::drainInputBuffer(BufferInfo *info) {
|
||||
}
|
||||
|
||||
info->mOwnedByComponent = true;
|
||||
|
||||
// This component does not ever signal the EOS flag on output buffers,
|
||||
// Thanks for nothing.
|
||||
if (mSignalledEOS && !strcmp(mComponentName, "OMX.TI.Video.encoder")) {
|
||||
mNoMoreOutputData = true;
|
||||
mBufferFilled.signal();
|
||||
}
|
||||
}
|
||||
|
||||
void OMXCodec::fillOutputBuffer(BufferInfo *info) {
|
||||
|
||||
Reference in New Issue
Block a user