diff options
author | Andreas Huber <andih@google.com> | 2012-02-21 11:47:18 -0800 |
---|---|---|
committer | Andreas Huber <andih@google.com> | 2012-02-22 15:06:06 -0800 |
commit | 5778822d86b0337407514b9372562b86edfa91cd (patch) | |
tree | b8faf8188dfb8865bd88b4dfc778a7d9ab89bb73 /include/media/stagefright | |
parent | c33305c5dd4cc06e71eb0c66a7150aa6ab647c99 (diff) | |
download | frameworks_av-5778822d86b0337407514b9372562b86edfa91cd.zip frameworks_av-5778822d86b0337407514b9372562b86edfa91cd.tar.gz frameworks_av-5778822d86b0337407514b9372562b86edfa91cd.tar.bz2 |
Implementation of a java media codec interface and associated tools.
Change-Id: I13e54062d4de584355c5d82bb027a68aeaf2923b
Diffstat (limited to 'include/media/stagefright')
-rw-r--r-- | include/media/stagefright/ACodec.h | 43 | ||||
-rw-r--r-- | include/media/stagefright/MediaCodec.h | 183 | ||||
-rw-r--r-- | include/media/stagefright/MediaErrors.h | 1 | ||||
-rw-r--r-- | include/media/stagefright/NativeWindowWrapper.h | 26 | ||||
-rw-r--r-- | include/media/stagefright/NuMediaExtractor.h | 80 | ||||
-rw-r--r-- | include/media/stagefright/foundation/AMessage.h | 13 |
6 files changed, 316 insertions, 30 deletions
diff --git a/include/media/stagefright/ACodec.h b/include/media/stagefright/ACodec.h index 3963d9c..70799a6 100644 --- a/include/media/stagefright/ACodec.h +++ b/include/media/stagefright/ACodec.h @@ -22,6 +22,7 @@ #include <android/native_window.h> #include <media/IOMX.h> #include <media/stagefright/foundation/AHierarchicalStateMachine.h> +#include <OMX_Audio.h> namespace android { @@ -37,6 +38,9 @@ struct ACodec : public AHierarchicalStateMachine { kWhatFlushCompleted = 'fcom', kWhatOutputFormatChanged = 'outC', kWhatError = 'erro', + kWhatComponentAllocated = 'cAll', + kWhatComponentConfigured = 'cCon', + kWhatBuffersAllocated = 'allc', }; ACodec(); @@ -47,6 +51,10 @@ struct ACodec : public AHierarchicalStateMachine { void signalResume(); void initiateShutdown(); + void initiateAllocateComponent(const sp<AMessage> &msg); + void initiateConfigureComponent(const sp<AMessage> &msg); + void initiateStart(); + protected: virtual ~ACodec(); @@ -70,6 +78,9 @@ private: kWhatFlush = 'flus', kWhatResume = 'resm', kWhatDrainDeferredMessages = 'drai', + kWhatAllocateComponent = 'allo', + kWhatConfigureComponent = 'conf', + kWhatStart = 'star', }; enum { @@ -118,6 +129,7 @@ private: List<sp<AMessage> > mDeferredQueue; bool mSentFormat; + bool mIsEncoder; status_t allocateBuffersOnPort(OMX_U32 portIndex); status_t freeBuffersOnPort(OMX_U32 portIndex); @@ -132,8 +144,8 @@ private: uint32_t portIndex, IOMX::buffer_id bufferID, ssize_t *index = NULL); - void setComponentRole(bool isEncoder, const char *mime); - void configureCodec(const char *mime, const sp<AMessage> &msg); + status_t setComponentRole(bool isEncoder, const char *mime); + status_t configureCodec(const char *mime, const sp<AMessage> &msg); status_t setVideoPortFormatType( OMX_U32 portIndex, @@ -145,20 +157,37 @@ private: status_t setupVideoDecoder( const char *mime, int32_t width, int32_t height); + status_t setupVideoEncoder( + const char *mime, const sp<AMessage> &msg); + status_t setVideoFormatOnPort( OMX_U32 portIndex, int32_t width, int32_t height, OMX_VIDEO_CODINGTYPE compressionFormat); - status_t setupAACDecoder(int32_t numChannels, int32_t sampleRate); - status_t setupAMRDecoder(bool isWAMR); - status_t setupG711Decoder(int32_t numChannels); + status_t setupAACCodec( + bool encoder, + int32_t numChannels, int32_t sampleRate, int32_t bitRate); + + status_t selectAudioPortFormat( + OMX_U32 portIndex, OMX_AUDIO_CODINGTYPE desiredFormat); + + status_t setupAMRCodec(bool encoder, bool isWAMR, int32_t bitRate); + status_t setupG711Codec(bool encoder, int32_t numChannels); status_t setupRawAudioFormat( OMX_U32 portIndex, int32_t sampleRate, int32_t numChannels); status_t setMinBufferSize(OMX_U32 portIndex, size_t size); + status_t setupMPEG4EncoderParameters(const sp<AMessage> &msg); + status_t setupH263EncoderParameters(const sp<AMessage> &msg); + status_t setupAVCEncoderParameters(const sp<AMessage> &msg); + + status_t verifySupportForProfileAndLevel(int32_t profile, int32_t level); + status_t configureBitrate(int32_t bitrate); + status_t setupErrorCorrectionParameters(); + status_t initNativeWindow(); // Returns true iff all buffers on the given port have status OWNED_BY_US. @@ -173,7 +202,9 @@ private: void sendFormatChange(); - void signalError(OMX_ERRORTYPE error = OMX_ErrorUndefined); + void signalError( + OMX_ERRORTYPE error = OMX_ErrorUndefined, + status_t internalError = UNKNOWN_ERROR); DISALLOW_EVIL_CONSTRUCTORS(ACodec); }; diff --git a/include/media/stagefright/MediaCodec.h b/include/media/stagefright/MediaCodec.h new file mode 100644 index 0000000..8c11c9c --- /dev/null +++ b/include/media/stagefright/MediaCodec.h @@ -0,0 +1,183 @@ +/* + * Copyright 2012, 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_CODEC_H_ + +#define MEDIA_CODEC_H_ + +#include <gui/ISurfaceTexture.h> +#include <media/stagefright/foundation/AHandler.h> +#include <utils/Vector.h> + +namespace android { + +struct ABuffer; +struct ACodec; +struct AMessage; +struct SoftwareRenderer; +struct SurfaceTextureClient; + +struct MediaCodec : public AHandler { + enum ConfigureFlags { + CONFIGURE_FLAG_ENCODE = 1, + }; + + enum BufferFlags { + BUFFER_FLAG_SYNCFRAME = 1, + BUFFER_FLAG_CODECCONFIG = 2, + BUFFER_FLAG_EOS = 4, + }; + + static sp<MediaCodec> CreateByType( + const sp<ALooper> &looper, const char *mime, bool encoder); + + static sp<MediaCodec> CreateByComponentName( + const sp<ALooper> &looper, const char *name); + + status_t configure( + const sp<AMessage> &format, + const sp<SurfaceTextureClient> &nativeWindow, + uint32_t flags); + + status_t start(); + status_t stop(); + + status_t flush(); + + status_t queueInputBuffer( + size_t index, + size_t offset, + size_t size, + int64_t presentationTimeUs, + uint32_t flags); + + status_t dequeueInputBuffer(size_t *index, int64_t timeoutUs = 0ll); + + status_t dequeueOutputBuffer( + size_t *index, + size_t *offset, + size_t *size, + int64_t *presentationTimeUs, + uint32_t *flags, + int64_t timeoutUs = 0ll); + + status_t renderOutputBufferAndRelease(size_t index); + status_t releaseOutputBuffer(size_t index); + + status_t getOutputFormat(sp<AMessage> *format) const; + + status_t getInputBuffers(Vector<sp<ABuffer> > *buffers) const; + status_t getOutputBuffers(Vector<sp<ABuffer> > *buffers) const; + +protected: + virtual ~MediaCodec(); + virtual void onMessageReceived(const sp<AMessage> &msg); + +private: + enum State { + UNINITIALIZED, + INITIALIZING, + INITIALIZED, + CONFIGURING, + CONFIGURED, + STARTING, + STARTED, + FLUSHING, + STOPPING, + }; + + enum { + kPortIndexInput = 0, + kPortIndexOutput = 1, + }; + + enum { + kWhatInit = 'init', + kWhatConfigure = 'conf', + kWhatStart = 'strt', + kWhatStop = 'stop', + kWhatDequeueInputBuffer = 'deqI', + kWhatQueueInputBuffer = 'queI', + kWhatDequeueOutputBuffer = 'deqO', + kWhatReleaseOutputBuffer = 'relO', + kWhatGetBuffers = 'getB', + kWhatFlush = 'flus', + kWhatGetOutputFormat = 'getO', + kWhatDequeueInputTimedOut = 'dITO', + kWhatDequeueOutputTimedOut = 'dOTO', + kWhatCodecNotify = 'codc', + }; + + enum { + kFlagIsSoftwareCodec = 1, + kFlagOutputFormatChanged = 2, + kFlagOutputBuffersChanged = 4, + kFlagStickyError = 8, + kFlagDequeueInputPending = 16, + kFlagDequeueOutputPending = 32, + }; + + struct BufferInfo { + void *mBufferID; + sp<ABuffer> mData; + sp<AMessage> mNotify; + bool mOwnedByClient; + }; + + State mState; + sp<ALooper> mLooper; + sp<ALooper> mCodecLooper; + sp<ACodec> mCodec; + uint32_t mReplyID; + uint32_t mFlags; + sp<SurfaceTextureClient> mNativeWindow; + SoftwareRenderer *mSoftRenderer; + sp<AMessage> mOutputFormat; + + List<size_t> mAvailPortBuffers[2]; + Vector<BufferInfo> mPortBuffers[2]; + + int32_t mDequeueInputTimeoutGeneration; + uint32_t mDequeueInputReplyID; + + int32_t mDequeueOutputTimeoutGeneration; + uint32_t mDequeueOutputReplyID; + + MediaCodec(const sp<ALooper> &looper); + + static status_t PostAndAwaitResponse( + const sp<AMessage> &msg, sp<AMessage> *response); + + status_t init(const char *name, bool nameIsType, bool encoder); + + void setState(State newState); + void returnBuffersToCodec(); + void returnBuffersToCodecOnPort(int32_t portIndex); + size_t updateBuffers(int32_t portIndex, const sp<AMessage> &msg); + status_t onQueueInputBuffer(const sp<AMessage> &msg); + status_t onReleaseOutputBuffer(const sp<AMessage> &msg); + ssize_t dequeuePortBuffer(int32_t portIndex); + + bool handleDequeueInputBuffer(uint32_t replyID, bool newRequest = false); + bool handleDequeueOutputBuffer(uint32_t replyID, bool newRequest = false); + void cancelPendingDequeueOperations(); + + DISALLOW_EVIL_CONSTRUCTORS(MediaCodec); +}; + +} // namespace android + +#endif // MEDIA_CODEC_H_ diff --git a/include/media/stagefright/MediaErrors.h b/include/media/stagefright/MediaErrors.h index 21d00b8..dd3bf28 100644 --- a/include/media/stagefright/MediaErrors.h +++ b/include/media/stagefright/MediaErrors.h @@ -40,6 +40,7 @@ enum { // Not technically an error. INFO_FORMAT_CHANGED = MEDIA_ERROR_BASE - 12, INFO_DISCONTINUITY = MEDIA_ERROR_BASE - 13, + INFO_OUTPUT_BUFFERS_CHANGED = MEDIA_ERROR_BASE - 14, // The following constant values should be in sync with // drm/drm_framework_common.h diff --git a/include/media/stagefright/NativeWindowWrapper.h b/include/media/stagefright/NativeWindowWrapper.h index f323cbc..97cc0ce 100644 --- a/include/media/stagefright/NativeWindowWrapper.h +++ b/include/media/stagefright/NativeWindowWrapper.h @@ -18,40 +18,28 @@ #define NATIVE_WINDOW_WRAPPER_H_ -#include <surfaceflinger/Surface.h> #include <gui/SurfaceTextureClient.h> namespace android { -// Both Surface and SurfaceTextureClient are RefBase that implement the -// ANativeWindow interface, but at different addresses. ANativeWindow is not -// a RefBase but acts like one for use with sp<>. This wrapper converts a -// Surface or SurfaceTextureClient into a single reference-counted object -// that holds an sp reference to the underlying Surface or SurfaceTextureClient, -// It provides a method to get the ANativeWindow. +// SurfaceTextureClient derives from ANativeWindow which derives from multiple +// base classes, in order to carry it in AMessages, we'll temporarily wrap it +// into a NativeWindowWrapper. struct NativeWindowWrapper : RefBase { NativeWindowWrapper( - const sp<Surface> &surface) : - mSurface(surface) { } - - NativeWindowWrapper( const sp<SurfaceTextureClient> &surfaceTextureClient) : mSurfaceTextureClient(surfaceTextureClient) { } sp<ANativeWindow> getNativeWindow() const { - if (mSurface != NULL) { - return mSurface; - } else { - return mSurfaceTextureClient; - } + return mSurfaceTextureClient; } - // If needed later we can provide a method to ask what kind of native window + sp<SurfaceTextureClient> getSurfaceTextureClient() const { + return mSurfaceTextureClient; + } private: - // At most one of mSurface and mSurfaceTextureClient will be non-NULL - const sp<Surface> mSurface; const sp<SurfaceTextureClient> mSurfaceTextureClient; DISALLOW_EVIL_CONSTRUCTORS(NativeWindowWrapper); diff --git a/include/media/stagefright/NuMediaExtractor.h b/include/media/stagefright/NuMediaExtractor.h new file mode 100644 index 0000000..96efdff --- /dev/null +++ b/include/media/stagefright/NuMediaExtractor.h @@ -0,0 +1,80 @@ +/* + * Copyright 2012, 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 NU_MEDIA_EXTRACTOR_H_ +#define NU_MEDIA_EXTRACTOR_H_ + +#include <media/stagefright/foundation/ABase.h> +#include <utils/Errors.h> +#include <utils/RefBase.h> +#include <utils/Vector.h> + +namespace android { + +struct ABuffer; +struct AMessage; +struct MediaBuffer; +struct MediaExtractor; +struct MediaSource; + +struct NuMediaExtractor : public RefBase { + NuMediaExtractor(); + + status_t setDataSource(const char *path); + + size_t countTracks() const; + status_t getTrackFormat(size_t index, sp<AMessage> *format) const; + + status_t selectTrack(size_t index); + + status_t seekTo(int64_t timeUs); + + status_t advance(); + status_t readSampleData(const sp<ABuffer> &buffer); + status_t getSampleTrackIndex(size_t *trackIndex); + status_t getSampleTime(int64_t *sampleTimeUs); + +protected: + virtual ~NuMediaExtractor(); + +private: + enum TrackFlags { + kIsVorbis = 1, + }; + + struct TrackInfo { + sp<MediaSource> mSource; + size_t mTrackIndex; + status_t mFinalResult; + MediaBuffer *mSample; + int64_t mSampleTimeUs; + uint32_t mFlags; // bitmask of "TrackFlags" + }; + + sp<MediaExtractor> mImpl; + + Vector<TrackInfo> mSelectedTracks; + + ssize_t fetchTrackSamples(int64_t seekTimeUs = -1ll); + void releaseTrackSamples(); + + DISALLOW_EVIL_CONSTRUCTORS(NuMediaExtractor); +}; + +} // namespace android + +#endif // NU_MEDIA_EXTRACTOR_H_ + diff --git a/include/media/stagefright/foundation/AMessage.h b/include/media/stagefright/foundation/AMessage.h index 7ec54aa..50455e8 100644 --- a/include/media/stagefright/foundation/AMessage.h +++ b/include/media/stagefright/foundation/AMessage.h @@ -90,10 +90,6 @@ struct AMessage : public RefBase { AString debugString(int32_t indent = 0) const; -protected: - virtual ~AMessage(); - -private: enum Type { kTypeInt32, kTypeInt64, @@ -107,6 +103,13 @@ private: kTypeRect, }; + size_t countEntries() const; + const char *getEntryNameAt(size_t index, Type *type) const; + +protected: + virtual ~AMessage(); + +private: uint32_t mWhat; ALooper::handler_id mTarget; @@ -131,7 +134,7 @@ private: }; enum { - kMaxNumItems = 16 + kMaxNumItems = 32 }; Item mItems[kMaxNumItems]; size_t mNumItems; |