diff options
Diffstat (limited to 'include')
51 files changed, 922 insertions, 403 deletions
diff --git a/include/camera/CameraParameters2.h b/include/camera/CameraParameters2.h deleted file mode 100644 index 88ad812..0000000 --- a/include/camera/CameraParameters2.h +++ /dev/null @@ -1,203 +0,0 @@ -/* - * Copyright (C) 2014 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 ANDROID_HARDWARE_CAMERA_PARAMETERS2_H -#define ANDROID_HARDWARE_CAMERA_PARAMETERS2_H - -#include <utils/Vector.h> -#include <utils/String8.h> -#include "CameraParameters.h" - -namespace android { - -/** - * A copy of CameraParameters plus ABI-breaking changes. Needed - * because some camera HALs directly link to CameraParameters and cannot - * tolerate an ABI change. - */ -class CameraParameters2 -{ -public: - CameraParameters2(); - CameraParameters2(const String8 ¶ms) { unflatten(params); } - ~CameraParameters2(); - - String8 flatten() const; - void unflatten(const String8 ¶ms); - - void set(const char *key, const char *value); - void set(const char *key, int value); - void setFloat(const char *key, float value); - // Look up string value by key. - // -- The string remains valid until the next set/remove of the same key, - // or until the map gets cleared. - const char *get(const char *key) const; - int getInt(const char *key) const; - float getFloat(const char *key) const; - - // Compare the order that key1 was set vs the order that key2 was set. - // - // Sets the order parameter to an integer less than, equal to, or greater - // than zero if key1's set order was respectively, to be less than, to - // match, or to be greater than key2's set order. - // - // Error codes: - // * NAME_NOT_FOUND - if either key has not been set previously - // * BAD_VALUE - if any of the parameters are NULL - status_t compareSetOrder(const char *key1, const char *key2, - /*out*/ - int *order) const; - - void remove(const char *key); - - void setPreviewSize(int width, int height); - void getPreviewSize(int *width, int *height) const; - void getSupportedPreviewSizes(Vector<Size> &sizes) const; - - // Set the dimensions in pixels to the given width and height - // for video frames. The given width and height must be one - // of the supported dimensions returned from - // getSupportedVideoSizes(). Must not be called if - // getSupportedVideoSizes() returns an empty Vector of Size. - void setVideoSize(int width, int height); - // Retrieve the current dimensions (width and height) - // in pixels for video frames, which must be one of the - // supported dimensions returned from getSupportedVideoSizes(). - // Must not be called if getSupportedVideoSizes() returns an - // empty Vector of Size. - void getVideoSize(int *width, int *height) const; - // Retrieve a Vector of supported dimensions (width and height) - // in pixels for video frames. If sizes returned from the method - // is empty, the camera does not support calls to setVideoSize() - // or getVideoSize(). In adddition, it also indicates that - // the camera only has a single output, and does not have - // separate output for video frames and preview frame. - void getSupportedVideoSizes(Vector<Size> &sizes) const; - // Retrieve the preferred preview size (width and height) in pixels - // for video recording. The given width and height must be one of - // supported preview sizes returned from getSupportedPreviewSizes(). - // Must not be called if getSupportedVideoSizes() returns an empty - // Vector of Size. If getSupportedVideoSizes() returns an empty - // Vector of Size, the width and height returned from this method - // is invalid, and is "-1x-1". - void getPreferredPreviewSizeForVideo(int *width, int *height) const; - - void setPreviewFrameRate(int fps); - int getPreviewFrameRate() const; - void getPreviewFpsRange(int *min_fps, int *max_fps) const; - void setPreviewFpsRange(int min_fps, int max_fps); - void setPreviewFormat(const char *format); - const char *getPreviewFormat() const; - void setPictureSize(int width, int height); - void getPictureSize(int *width, int *height) const; - void getSupportedPictureSizes(Vector<Size> &sizes) const; - void setPictureFormat(const char *format); - const char *getPictureFormat() const; - - void dump() const; - status_t dump(int fd, const Vector<String16>& args) const; - -private: - - // Quick and dirty map that maintains insertion order - template <typename KeyT, typename ValueT> - struct OrderedKeyedVector { - - ssize_t add(const KeyT& key, const ValueT& value) { - return mList.add(Pair(key, value)); - } - - size_t size() const { - return mList.size(); - } - - const KeyT& keyAt(size_t idx) const { - return mList[idx].mKey; - } - - const ValueT& valueAt(size_t idx) const { - return mList[idx].mValue; - } - - const ValueT& valueFor(const KeyT& key) const { - ssize_t i = indexOfKey(key); - LOG_ALWAYS_FATAL_IF(i<0, "%s: key not found", __PRETTY_FUNCTION__); - - return valueAt(i); - } - - ssize_t indexOfKey(const KeyT& key) const { - size_t vectorIdx = 0; - for (; vectorIdx < mList.size(); ++vectorIdx) { - if (mList[vectorIdx].mKey == key) { - return (ssize_t) vectorIdx; - } - } - - return NAME_NOT_FOUND; - } - - ssize_t removeItem(const KeyT& key) { - size_t vectorIdx = (size_t) indexOfKey(key); - - if (vectorIdx < 0) { - return vectorIdx; - } - - return mList.removeAt(vectorIdx); - } - - void clear() { - mList.clear(); - } - - // Same as removing and re-adding. The key's index changes to max. - ssize_t replaceValueFor(const KeyT& key, const ValueT& value) { - removeItem(key); - return add(key, value); - } - - private: - - struct Pair { - Pair() : mKey(), mValue() {} - Pair(const KeyT& key, const ValueT& value) : - mKey(key), - mValue(value) {} - KeyT mKey; - ValueT mValue; - }; - - Vector<Pair> mList; - }; - - /** - * Order matters: Keys that are set() later are stored later in the map. - * - * If two keys have meaning that conflict, then the later-set key - * wins. - * - * For example, preview FPS and preview FPS range conflict since only - * we only want to use the FPS range if that's the last thing that was set. - * So in that case, only use preview FPS range if it was set later than - * the preview FPS. - */ - OrderedKeyedVector<String8,String8> mMap; -}; - -}; // namespace android - -#endif diff --git a/include/camera/CaptureResult.h b/include/camera/CaptureResult.h new file mode 100644 index 0000000..6e47a16 --- /dev/null +++ b/include/camera/CaptureResult.h @@ -0,0 +1,90 @@ +/* + * Copyright (C) 2014 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 ANDROID_HARDWARE_CAPTURERESULT_H +#define ANDROID_HARDWARE_CAPTURERESULT_H + +#include <utils/RefBase.h> +#include <camera/CameraMetadata.h> + +namespace android { + +/** + * CaptureResultExtras is a structure to encapsulate various indices for a capture result. + * These indices are framework-internal and not sent to the HAL. + */ +struct CaptureResultExtras { + /** + * An integer to index the request sequence that this result belongs to. + */ + int32_t requestId; + + /** + * An integer to index this result inside a request sequence, starting from 0. + */ + int32_t burstId; + + /** + * TODO: Add documentation for this field. + */ + int32_t afTriggerId; + + /** + * TODO: Add documentation for this field. + */ + int32_t precaptureTriggerId; + + /** + * A 64bit integer to index the frame number associated with this result. + */ + int64_t frameNumber; + + /** + * Constructor initializes object as invalid by setting requestId to be -1. + */ + CaptureResultExtras() + : requestId(-1), + burstId(0), + afTriggerId(0), + precaptureTriggerId(0), + frameNumber(0) { + } + + /** + * This function returns true if it's a valid CaptureResultExtras object. + * Otherwise, returns false. It is valid only when requestId is non-negative. + */ + bool isValid(); + + status_t readFromParcel(Parcel* parcel); + status_t writeToParcel(Parcel* parcel) const; +}; + +struct CaptureResult : public virtual LightRefBase<CaptureResult> { + CameraMetadata mMetadata; + CaptureResultExtras mResultExtras; + + CaptureResult(); + + CaptureResult(const CaptureResult& otherResult); + + status_t readFromParcel(Parcel* parcel); + status_t writeToParcel(Parcel* parcel) const; +}; + +} + +#endif /* ANDROID_HARDWARE_CAPTURERESULT_H */ diff --git a/include/camera/ICameraService.h b/include/camera/ICameraService.h index f342122..6e48f22 100644 --- a/include/camera/ICameraService.h +++ b/include/camera/ICameraService.h @@ -31,6 +31,7 @@ class ICameraServiceListener; class ICameraDeviceUser; class ICameraDeviceCallbacks; class CameraMetadata; +class VendorTagDescriptor; class ICameraService : public IInterface { @@ -47,6 +48,7 @@ public: ADD_LISTENER, REMOVE_LISTENER, GET_CAMERA_CHARACTERISTICS, + GET_CAMERA_VENDOR_TAG_DESCRIPTOR, }; enum { @@ -58,10 +60,16 @@ public: virtual int32_t getNumberOfCameras() = 0; virtual status_t getCameraInfo(int cameraId, - struct CameraInfo* cameraInfo) = 0; + /*out*/ + struct CameraInfo* cameraInfo) = 0; virtual status_t getCameraCharacteristics(int cameraId, - CameraMetadata* cameraInfo) = 0; + /*out*/ + CameraMetadata* cameraInfo) = 0; + + virtual status_t getCameraVendorTagDescriptor( + /*out*/ + sp<VendorTagDescriptor>& desc) = 0; // Returns 'OK' if operation succeeded // - Errors: ALREADY_EXISTS if the listener was already added diff --git a/include/camera/VendorTagDescriptor.h b/include/camera/VendorTagDescriptor.h new file mode 100644 index 0000000..ea21d31 --- /dev/null +++ b/include/camera/VendorTagDescriptor.h @@ -0,0 +1,124 @@ +/* + * Copyright (C) 2014 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 VENDOR_TAG_DESCRIPTOR_H + +#include <utils/KeyedVector.h> +#include <utils/String8.h> +#include <utils/RefBase.h> +#include <system/camera_vendor_tags.h> + +#include <stdint.h> + +namespace android { + +class Parcel; + +/** + * VendorTagDescriptor objects are parcelable containers for the vendor tag + * definitions provided, and are typically used to pass the vendor tag + * information enumerated by the HAL to clients of the camera service. + */ +class VendorTagDescriptor + : public LightRefBase<VendorTagDescriptor> { + public: + virtual ~VendorTagDescriptor(); + + /** + * The following 'get*' methods implement the corresponding + * functions defined in + * system/media/camera/include/system/camera_vendor_tags.h + */ + + // Returns the number of vendor tags defined. + int getTagCount() const; + + // Returns an array containing the id's of vendor tags defined. + void getTagArray(uint32_t* tagArray) const; + + // Returns the section name string for a given vendor tag id. + const char* getSectionName(uint32_t tag) const; + + // Returns the tag name string for a given vendor tag id. + const char* getTagName(uint32_t tag) const; + + // Returns the tag type for a given vendor tag id. + int getTagType(uint32_t tag) const; + + /** + * Write the VendorTagDescriptor object into the given parcel. + * + * Returns OK on success, or a negative error code. + */ + status_t writeToParcel( + /*out*/ + Parcel* parcel) const; + + // Static methods: + + /** + * Create a VendorTagDescriptor object from the given parcel. + * + * Returns OK on success, or a negative error code. + */ + static status_t createFromParcel(const Parcel* parcel, + /*out*/ + sp<VendorTagDescriptor>& descriptor); + + /** + * Create a VendorTagDescriptor object from the given vendor_tag_ops_t + * struct. + * + * Returns OK on success, or a negative error code. + */ + static status_t createDescriptorFromOps(const vendor_tag_ops_t* vOps, + /*out*/ + sp<VendorTagDescriptor>& descriptor); + + /** + * Sets the global vendor tag descriptor to use for this process. + * Camera metadata operations that access vendor tags will use the + * vendor tag definitions set this way. + * + * Returns OK on success, or a negative error code. + */ + static status_t setAsGlobalVendorTagDescriptor(const sp<VendorTagDescriptor>& desc); + + /** + * Clears the global vendor tag descriptor used by this process. + */ + static void clearGlobalVendorTagDescriptor(); + + /** + * Returns the global vendor tag descriptor used by this process. + * This will contain NULL if no vendor tags are defined. + */ + static sp<VendorTagDescriptor> getGlobalVendorTagDescriptor(); + protected: + VendorTagDescriptor(); + KeyedVector<uint32_t, String8> mTagToNameMap; + KeyedVector<uint32_t, String8> mTagToSectionMap; + KeyedVector<uint32_t, int32_t> mTagToTypeMap; + // must be int32_t to be compatible with Parcel::writeInt32 + int32_t mTagCount; + private: + vendor_tag_ops mVendorOps; +}; + +} /* namespace android */ + +#define VENDOR_TAG_DESCRIPTOR_H +#endif /* VENDOR_TAG_DESCRIPTOR_H */ diff --git a/include/camera/camera2/ICameraDeviceCallbacks.h b/include/camera/camera2/ICameraDeviceCallbacks.h index 8dac4f2..f059b3d 100644 --- a/include/camera/camera2/ICameraDeviceCallbacks.h +++ b/include/camera/camera2/ICameraDeviceCallbacks.h @@ -24,9 +24,12 @@ #include <utils/Timers.h> #include <system/camera.h> +#include <camera/CaptureResult.h> + namespace android { class CameraMetadata; + class ICameraDeviceCallbacks : public IInterface { /** @@ -45,18 +48,19 @@ public: }; // One way - virtual void onDeviceError(CameraErrorCode errorCode) = 0; + virtual void onDeviceError(CameraErrorCode errorCode, + const CaptureResultExtras& resultExtras) = 0; // One way virtual void onDeviceIdle() = 0; // One way - virtual void onCaptureStarted(int32_t requestId, + virtual void onCaptureStarted(const CaptureResultExtras& resultExtras, int64_t timestamp) = 0; // One way - virtual void onResultReceived(int32_t requestId, - const CameraMetadata& result) = 0; + virtual void onResultReceived(const CameraMetadata& metadata, + const CaptureResultExtras& resultExtras) = 0; }; // ---------------------------------------------------------------------------- diff --git a/include/camera/camera2/ICameraDeviceUser.h b/include/camera/camera2/ICameraDeviceUser.h index f71f302..913696f 100644 --- a/include/camera/camera2/ICameraDeviceUser.h +++ b/include/camera/camera2/ICameraDeviceUser.h @@ -19,6 +19,7 @@ #include <binder/IInterface.h> #include <binder/Parcel.h> +#include <utils/List.h> struct camera_metadata; @@ -30,6 +31,10 @@ class Surface; class CaptureRequest; class CameraMetadata; +enum { + NO_IN_FLIGHT_REPEATING_FRAMES = -1, +}; + class ICameraDeviceUser : public IInterface { /** @@ -44,9 +49,34 @@ public: * Request Handling **/ + /** + * For streaming requests, output lastFrameNumber is the last frame number + * of the previous repeating request. + * For non-streaming requests, output lastFrameNumber is the expected last + * frame number of the current request. + */ virtual int submitRequest(sp<CaptureRequest> request, - bool streaming = false) = 0; - virtual status_t cancelRequest(int requestId) = 0; + bool streaming = false, + /*out*/ + int64_t* lastFrameNumber = NULL) = 0; + + /** + * For streaming requests, output lastFrameNumber is the last frame number + * of the previous repeating request. + * For non-streaming requests, output lastFrameNumber is the expected last + * frame number of the current request. + */ + virtual int submitRequestList(List<sp<CaptureRequest> > requestList, + bool streaming = false, + /*out*/ + int64_t* lastFrameNumber = NULL) = 0; + + /** + * Output lastFrameNumber is the last frame number of the previous repeating request. + */ + virtual status_t cancelRequest(int requestId, + /*out*/ + int64_t* lastFrameNumber = NULL) = 0; virtual status_t deleteStream(int streamId) = 0; virtual status_t createStream( @@ -64,8 +94,12 @@ public: // Wait until all the submitted requests have finished processing virtual status_t waitUntilIdle() = 0; - // Flush all pending and in-progress work as quickly as possible. - virtual status_t flush() = 0; + /** + * Flush all pending and in-progress work as quickly as possible. + * Output lastFrameNumber is the last frame number of the previous repeating request. + */ + virtual status_t flush(/*out*/ + int64_t* lastFrameNumber = NULL) = 0; }; // ---------------------------------------------------------------------------- diff --git a/include/media/AudioBufferProvider.h b/include/media/AudioBufferProvider.h index ef392f0..7be449c 100644 --- a/include/media/AudioBufferProvider.h +++ b/include/media/AudioBufferProvider.h @@ -61,6 +61,17 @@ public: // buffer->frameCount 0 virtual status_t getNextBuffer(Buffer* buffer, int64_t pts = kInvalidPTS) = 0; + // Release (a portion of) the buffer previously obtained by getNextBuffer(). + // It is permissible to call releaseBuffer() multiple times per getNextBuffer(). + // On entry: + // buffer->frameCount number of frames to release, must be <= number of frames + // obtained but not yet released + // buffer->raw unused + // On return: + // buffer->frameCount 0; implementation MUST set to zero + // buffer->raw undefined; implementation is PERMITTED to set to any value, + // so if caller needs to continue using this buffer it must + // keep track of the pointer itself virtual void releaseBuffer(Buffer* buffer) = 0; }; diff --git a/include/media/AudioEffect.h b/include/media/AudioEffect.h index 05d834d..f98002d 100644 --- a/include/media/AudioEffect.h +++ b/include/media/AudioEffect.h @@ -36,7 +36,7 @@ namespace android { // ---------------------------------------------------------------------------- -class effect_param_cblk_t; +struct effect_param_cblk_t; // ---------------------------------------------------------------------------- @@ -217,8 +217,9 @@ public: * higher priorities, 0 being the normal priority. * cbf: optional callback function (see effect_callback_t) * user: pointer to context for use by the callback receiver. - * sessionID: audio session this effect is associated to. If 0, the effect will be global to - * the output mix. If not 0, the effect will be applied to all players + * sessionID: audio session this effect is associated to. + * If equal to AUDIO_SESSION_OUTPUT_MIX, the effect will be global to + * the output mix. Otherwise, the effect will be applied to all players * (AudioTrack or MediaPLayer) within the same audio session. * io: HAL audio output or input stream to which this effect must be attached. Leave at 0 for * automatic output selection by AudioFlinger. @@ -229,8 +230,8 @@ public: int32_t priority = 0, effect_callback_t cbf = NULL, void* user = NULL, - int sessionId = 0, - audio_io_handle_t io = 0 + int sessionId = AUDIO_SESSION_OUTPUT_MIX, + audio_io_handle_t io = AUDIO_IO_HANDLE_NONE ); /* Constructor. @@ -241,8 +242,8 @@ public: int32_t priority = 0, effect_callback_t cbf = NULL, void* user = NULL, - int sessionId = 0, - audio_io_handle_t io = 0 + int sessionId = AUDIO_SESSION_OUTPUT_MIX, + audio_io_handle_t io = AUDIO_IO_HANDLE_NONE ); /* Terminates the AudioEffect and unregisters it from AudioFlinger. @@ -263,8 +264,8 @@ public: int32_t priority = 0, effect_callback_t cbf = NULL, void* user = NULL, - int sessionId = 0, - audio_io_handle_t io = 0 + int sessionId = AUDIO_SESSION_OUTPUT_MIX, + audio_io_handle_t io = AUDIO_IO_HANDLE_NONE ); /* Result of constructing the AudioEffect. This must be checked diff --git a/include/media/AudioRecord.h b/include/media/AudioRecord.h index 052064d..b3c44a8 100644 --- a/include/media/AudioRecord.h +++ b/include/media/AudioRecord.h @@ -26,7 +26,7 @@ namespace android { // ---------------------------------------------------------------------------- -class audio_track_cblk_t; +struct audio_track_cblk_t; class AudioRecordClientProxy; // ---------------------------------------------------------------------------- @@ -39,8 +39,12 @@ public: * Keep in sync with frameworks/base/media/java/android/media/AudioRecord.java NATIVE_EVENT_*. */ enum event_type { - EVENT_MORE_DATA = 0, // Request to read more data from PCM buffer. - EVENT_OVERRUN = 1, // PCM buffer overrun occurred. + EVENT_MORE_DATA = 0, // Request to read available data from buffer. + // If this event is delivered but the callback handler + // does not want to read the available data, the handler must + // explicitly + // ignore the event by setting frameCount to zero. + EVENT_OVERRUN = 1, // Buffer overrun occurred. EVENT_MARKER = 2, // Record head is at the specified marker position // (See setMarkerPosition()). EVENT_NEW_POS = 3, // Record head is at a new position @@ -60,9 +64,10 @@ public: size_t frameCount; // number of sample frames corresponding to size; // on input it is the number of frames available, // on output is the number of frames actually drained - // (currently ignored, but will make the primary field in future) + // (currently ignored but will make the primary field in future) size_t size; // input/output in bytes == frameCount * frameSize + // on output is the number of bytes actually drained // FIXME this is redundant with respect to frameCount, // and TRANSFER_OBTAIN mode is broken for 8-bit data // since we don't define the frame format @@ -76,7 +81,7 @@ public: /* As a convenience, if a callback is supplied, a handler thread * is automatically created with the appropriate priority. This thread - * invokes the callback when a new buffer becomes ready or various conditions occur. + * invokes the callback when a new buffer becomes available or various conditions occur. * Parameters: * * event: type of event notified (see enum AudioRecord::event_type). @@ -99,6 +104,8 @@ public: * - NO_ERROR: successful operation * - NO_INIT: audio server or audio hardware not initialized * - BAD_VALUE: unsupported configuration + * frameCount is guaranteed to be non-zero if status is NO_ERROR, + * and is undefined otherwise. */ static status_t getMinFrameCount(size_t* frameCount, @@ -109,7 +116,7 @@ public: /* How data is transferred from AudioRecord */ enum transfer_type { - TRANSFER_DEFAULT, // not specified explicitly; determine from other parameters + TRANSFER_DEFAULT, // not specified explicitly; determine from the other parameters TRANSFER_CALLBACK, // callback EVENT_MORE_DATA TRANSFER_OBTAIN, // FIXME deprecated: call obtainBuffer() and releaseBuffer() TRANSFER_SYNC, // synchronous read() @@ -137,7 +144,7 @@ public: * be larger if the requested size is not compatible with current audio HAL * latency. Zero means to use a default value. * cbf: Callback function. If not null, this function is called periodically - * to consume new PCM data and inform of marker, position updates, etc. + * to consume new data and inform of marker, position updates, etc. * user: Context for use by the callback receiver. * notificationFrames: The callback function is called each time notificationFrames PCM * frames are ready in record track output buffer. @@ -151,11 +158,11 @@ public: uint32_t sampleRate, audio_format_t format, audio_channel_mask_t channelMask, - int frameCount = 0, + size_t frameCount = 0, callback_t cbf = NULL, void* user = NULL, - int notificationFrames = 0, - int sessionId = 0, + uint32_t notificationFrames = 0, + int sessionId = AUDIO_SESSION_ALLOCATE, transfer_type transferType = TRANSFER_DEFAULT, audio_input_flags_t flags = AUDIO_INPUT_FLAG_NONE); @@ -171,9 +178,10 @@ public: * Returned status (from utils/Errors.h) can be: * - NO_ERROR: successful intialization * - INVALID_OPERATION: AudioRecord is already initialized or record device is already in use - * - BAD_VALUE: invalid parameter (channels, format, sampleRate...) + * - BAD_VALUE: invalid parameter (channelMask, format, sampleRate...) * - NO_INIT: audio server or audio hardware not initialized * - PERMISSION_DENIED: recording is not allowed for the requesting process + * If status is not equal to NO_ERROR, don't call any other APIs on this AudioRecord. * * Parameters not listed in the AudioRecord constructors above: * @@ -183,16 +191,16 @@ public: uint32_t sampleRate, audio_format_t format, audio_channel_mask_t channelMask, - int frameCount = 0, + size_t frameCount = 0, callback_t cbf = NULL, void* user = NULL, - int notificationFrames = 0, + uint32_t notificationFrames = 0, bool threadCanCallJava = false, - int sessionId = 0, + int sessionId = AUDIO_SESSION_ALLOCATE, transfer_type transferType = TRANSFER_DEFAULT, audio_input_flags_t flags = AUDIO_INPUT_FLAG_NONE); - /* Result of constructing the AudioRecord. This must be checked + /* Result of constructing the AudioRecord. This must be checked for successful initialization * before using any AudioRecord API (except for set()), because using * an uninitialized AudioRecord produces undefined results. * See set() method above for possible return codes. @@ -221,7 +229,7 @@ public: status_t start(AudioSystem::sync_event_t event = AudioSystem::SYNC_EVENT_NONE, int triggerSession = 0); - /* Stop a track. If set, the callback will cease being called. Note that obtainBuffer() still + /* Stop a track. The callback will cease being called. Note that obtainBuffer() still * works and will drain buffers until the pool is exhausted, and then will return WOULD_BLOCK. */ void stop(); @@ -236,7 +244,7 @@ public: * a callback with event type EVENT_MARKER is called. Calling setMarkerPosition * with marker == 0 cancels marker notification callback. * To set a marker at a position which would compute as 0, - * a workaround is to the set the marker at a nearby position such as ~0 or 1. + * a workaround is to set the marker at a nearby position such as ~0 or 1. * If the AudioRecord has been opened with no callback function associated, * the operation will fail. * @@ -378,8 +386,10 @@ public: * returning the current value by this function call. Such loss typically occurs when the * user space process is blocked longer than the capacity of audio driver buffers. * Units: the number of input audio frames. + * FIXME The side-effect of resetting the counter may be incompatible with multi-client. + * Consider making it more like AudioTrack::getUnderrunFrames which doesn't have side effects. */ - unsigned int getInputFramesLost() const; + uint32_t getInputFramesLost() const; private: /* copying audio record objects is not allowed */ @@ -412,6 +422,7 @@ private: bool mPaused; // whether thread is requested to pause at next loop entry bool mPausedInt; // whether thread internally requests pause nsecs_t mPausedNs; // if mPausedInt then associated timeout, otherwise ignored + bool mIgnoreNextPausedInt; // whether to ignore next mPausedInt request }; // body of AudioRecordThread::threadLoop() @@ -422,9 +433,10 @@ private: // NS_INACTIVE inactive so don't run again until re-started // NS_NEVER never again static const nsecs_t NS_WHENEVER = -1, NS_INACTIVE = -2, NS_NEVER = -3; - nsecs_t processAudioBuffer(const sp<AudioRecordThread>& thread); + nsecs_t processAudioBuffer(); // caller must hold lock on mLock for all _l methods + status_t openRecord_l(size_t epoch); // FIXME enum is faster than strcmp() for parameter 'from' @@ -446,12 +458,13 @@ private: // notification callback uint32_t mNotificationFramesAct; // actual number of frames between each // notification callback - bool mRefreshRemaining; // processAudioBuffer() should refresh next 2 + bool mRefreshRemaining; // processAudioBuffer() should refresh + // mRemainingFrames and mRetryOnPartialBuffer // These are private to processAudioBuffer(), and are not protected by a lock uint32_t mRemainingFrames; // number of frames to request in obtainBuffer() bool mRetryOnPartialBuffer; // sleep and retry after partial obtainBuffer() - int mObservedSequence; // last observed value of mSequence + uint32_t mObservedSequence; // last observed value of mSequence uint32_t mMarkerPosition; // in wrapping (overflow) frame units bool mMarkerReached; @@ -460,9 +473,13 @@ private: status_t mStatus; + size_t mFrameCount; // corresponds to current IAudioRecord, value is + // reported back by AudioFlinger to the client + size_t mReqFrameCount; // frame count to request the first or next time + // a new IAudioRecord is needed, non-decreasing + // constant after constructor or set() uint32_t mSampleRate; - size_t mFrameCount; audio_format_t mFormat; uint32_t mChannelCount; size_t mFrameSize; // app-level frame size == AudioFlinger frame size @@ -473,12 +490,11 @@ private: int mSessionId; transfer_type mTransfer; - audio_io_handle_t mInput; // returned by AudioSystem::getInput() - - // may be changed if IAudioRecord object is re-created + // Next 4 fields may be changed if IAudioRecord is re-created, but always != 0 sp<IAudioRecord> mAudioRecord; sp<IMemory> mCblkMemory; audio_track_cblk_t* mCblk; // re-load after mLock.unlock() + audio_io_handle_t mInput; // returned by AudioSystem::getInput() int mPreviousPriority; // before start() SchedPolicy mPreviousSchedulingGroup; diff --git a/include/media/AudioSystem.h b/include/media/AudioSystem.h index 4c22412..402b479 100644 --- a/include/media/AudioSystem.h +++ b/include/media/AudioSystem.h @@ -67,20 +67,24 @@ public: // returns true in *state if tracks are active on the specified stream or have been active // in the past inPastMs milliseconds - static status_t isStreamActive(audio_stream_type_t stream, bool *state, uint32_t inPastMs = 0); + static status_t isStreamActive(audio_stream_type_t stream, bool *state, uint32_t inPastMs); // returns true in *state if tracks are active for what qualifies as remote playback // on the specified stream or have been active in the past inPastMs milliseconds. Remote // playback isn't mutually exclusive with local playback. static status_t isStreamActiveRemotely(audio_stream_type_t stream, bool *state, - uint32_t inPastMs = 0); + uint32_t inPastMs); // returns true in *state if a recorder is currently recording with the specified source static status_t isSourceActive(audio_source_t source, bool *state); // set/get audio hardware parameters. The function accepts a list of parameters // key value pairs in the form: key1=value1;key2=value2;... // Some keys are reserved for standard parameters (See AudioParameter class). + // The versions with audio_io_handle_t are intended for internal media framework use only. static status_t setParameters(audio_io_handle_t ioHandle, const String8& keyValuePairs); static String8 getParameters(audio_io_handle_t ioHandle, const String8& keys); + // The versions without audio_io_handle_t are intended for JNI. + static status_t setParameters(const String8& keyValuePairs); + static String8 getParameters(const String8& keys); static void setErrorCallback(audio_error_callback cb); @@ -90,12 +94,14 @@ public: static float linearToLog(int volume); static int logToLinear(float volume); + // Returned samplingRate and frameCount output values are guaranteed + // to be non-zero if status == NO_ERROR static status_t getOutputSamplingRate(uint32_t* samplingRate, - audio_stream_type_t stream = AUDIO_STREAM_DEFAULT); + audio_stream_type_t stream); static status_t getOutputFrameCount(size_t* frameCount, - audio_stream_type_t stream = AUDIO_STREAM_DEFAULT); + audio_stream_type_t stream); static status_t getOutputLatency(uint32_t* latency, - audio_stream_type_t stream = AUDIO_STREAM_DEFAULT); + audio_stream_type_t stream); static status_t getSamplingRate(audio_io_handle_t output, audio_stream_type_t streamType, uint32_t* samplingRate); @@ -107,19 +113,18 @@ public: // returns the audio output stream latency in ms. Corresponds to // audio_stream_out->get_latency() static status_t getLatency(audio_io_handle_t output, - audio_stream_type_t stream, uint32_t* latency); static bool routedToA2dpOutput(audio_stream_type_t streamType); + // return status NO_ERROR implies *buffSize > 0 static status_t getInputBufferSize(uint32_t sampleRate, audio_format_t format, audio_channel_mask_t channelMask, size_t* buffSize); static status_t setVoiceVolume(float volume); // return the number of audio frames written by AudioFlinger to audio HAL and - // audio dsp to DAC since the output on which the specified stream is playing - // has exited standby. + // audio dsp to DAC since the specified output I/O handle has exited standby. // returned status (from utils/Errors.h) can be: // - NO_ERROR: successful operation, halFrames and dspFrames point to valid data // - INVALID_OPERATION: Not supported on current hardware platform @@ -128,15 +133,20 @@ public: // necessary to check returned status before using the returned values. static status_t getRenderPosition(audio_io_handle_t output, uint32_t *halFrames, - uint32_t *dspFrames, - audio_stream_type_t stream = AUDIO_STREAM_DEFAULT); + uint32_t *dspFrames); // return the number of input frames lost by HAL implementation, or 0 if the handle is invalid - static size_t getInputFramesLost(audio_io_handle_t ioHandle); + static uint32_t getInputFramesLost(audio_io_handle_t ioHandle); + // Allocate a new audio session ID and return that new ID. + // If unable to contact AudioFlinger, returns AUDIO_SESSION_ALLOCATE instead. + // FIXME If AudioFlinger were to ever exhaust the session ID namespace, + // this method could fail by returning either AUDIO_SESSION_ALLOCATE + // or an unspecified existing session ID. static int newAudioSessionId(); - static void acquireAudioSessionId(int audioSession); - static void releaseAudioSessionId(int audioSession); + + static void acquireAudioSessionId(int audioSession, pid_t pid); + static void releaseAudioSessionId(int audioSession, pid_t pid); // types of io configuration change events received with ioConfigChanged() enum io_config_event { @@ -155,7 +165,8 @@ public: class OutputDescriptor { public: OutputDescriptor() - : samplingRate(0), format(AUDIO_FORMAT_DEFAULT), channelMask(0), frameCount(0), latency(0) {} + : samplingRate(0), format(AUDIO_FORMAT_DEFAULT), channelMask(0), frameCount(0), latency(0) + {} uint32_t samplingRate; audio_format_t format; @@ -193,24 +204,32 @@ public: static status_t setPhoneState(audio_mode_t state); static status_t setForceUse(audio_policy_force_use_t usage, audio_policy_forced_cfg_t config); static audio_policy_forced_cfg_t getForceUse(audio_policy_force_use_t usage); + + // Client must successfully hand off the handle reference to AudioFlinger via createTrack(), + // or release it with releaseOutput(). static audio_io_handle_t getOutput(audio_stream_type_t stream, uint32_t samplingRate = 0, audio_format_t format = AUDIO_FORMAT_DEFAULT, audio_channel_mask_t channelMask = AUDIO_CHANNEL_OUT_STEREO, audio_output_flags_t flags = AUDIO_OUTPUT_FLAG_NONE, const audio_offload_info_t *offloadInfo = NULL); + static status_t startOutput(audio_io_handle_t output, audio_stream_type_t stream, - int session = 0); + int session); static status_t stopOutput(audio_io_handle_t output, audio_stream_type_t stream, - int session = 0); + int session); static void releaseOutput(audio_io_handle_t output); + + // Client must successfully hand off the handle reference to AudioFlinger via openRecord(), + // or release it with releaseInput(). static audio_io_handle_t getInput(audio_source_t inputSource, - uint32_t samplingRate = 0, - audio_format_t format = AUDIO_FORMAT_DEFAULT, - audio_channel_mask_t channelMask = AUDIO_CHANNEL_IN_MONO, - int sessionId = 0); + uint32_t samplingRate, + audio_format_t format, + audio_channel_mask_t channelMask, + int sessionId); + static status_t startInput(audio_io_handle_t input); static status_t stopInput(audio_io_handle_t input); static void releaseInput(audio_io_handle_t input); @@ -302,8 +321,6 @@ private: static sp<IAudioPolicyService> gAudioPolicyService; - // mapping between stream types and outputs - static DefaultKeyedVector<audio_stream_type_t, audio_io_handle_t> gStreamOutputMap; // list of output descriptors containing cached parameters // (sampling rate, framecount, channel count...) static DefaultKeyedVector<audio_io_handle_t, OutputDescriptor *> gOutputs; diff --git a/include/media/AudioTimestamp.h b/include/media/AudioTimestamp.h index c29c7e5..99e9c3e 100644 --- a/include/media/AudioTimestamp.h +++ b/include/media/AudioTimestamp.h @@ -19,6 +19,8 @@ #include <time.h> +namespace android { + class AudioTimestamp { public: AudioTimestamp() : mPosition(0) { @@ -30,4 +32,6 @@ public: struct timespec mTime; // corresponding CLOCK_MONOTONIC when frame is expected to present }; +} // namespace + #endif // ANDROID_AUDIO_TIMESTAMP_H diff --git a/include/media/AudioTrack.h b/include/media/AudioTrack.h index 4736369..2c48bbf 100644 --- a/include/media/AudioTrack.h +++ b/include/media/AudioTrack.h @@ -27,7 +27,7 @@ namespace android { // ---------------------------------------------------------------------------- -class audio_track_cblk_t; +struct audio_track_cblk_t; class AudioTrackClientProxy; class StaticAudioTrackClientProxy; @@ -36,11 +36,6 @@ class StaticAudioTrackClientProxy; class AudioTrack : public RefBase { public: - enum channel_index { - MONO = 0, - LEFT = 0, - RIGHT = 1 - }; /* Events used by AudioTrack callback function (callback_t). * Keep in sync with frameworks/base/media/java/android/media/AudioTrack.java NATIVE_EVENT_*. @@ -82,6 +77,7 @@ public: // (currently ignored, but will make the primary field in future) size_t size; // input/output in bytes == frameCount * frameSize + // on input it is unused // on output is the number of bytes actually filled // FIXME this is redundant with respect to frameCount, // and TRANSFER_OBTAIN mode is broken for 8-bit data @@ -91,7 +87,7 @@ public: void* raw; short* i16; // signed 16-bit int8_t* i8; // unsigned 8-bit, offset by 0x80 - }; + }; // input: unused, output: pointer to buffer }; /* As a convenience, if a callback is supplied, a handler thread @@ -123,6 +119,8 @@ public: * - NO_ERROR: successful operation * - NO_INIT: audio server or audio hardware not initialized * - BAD_VALUE: unsupported configuration + * frameCount is guaranteed to be non-zero if status is NO_ERROR, + * and is undefined otherwise. */ static status_t getMinFrameCount(size_t* frameCount, @@ -158,7 +156,7 @@ public: * sampleRate: Data source sampling rate in Hz. * format: Audio format (e.g AUDIO_FORMAT_PCM_16_BIT for signed * 16 bits per sample). - * channelMask: Channel mask. + * channelMask: Channel mask, such that audio_is_output_channel(channelMask) is true. * frameCount: Minimum size of track PCM buffer in frames. This defines the * application's contribution to the * latency of the track. The actual size selected by the AudioTrack could be @@ -180,15 +178,16 @@ public: uint32_t sampleRate, audio_format_t format, audio_channel_mask_t, - int frameCount = 0, + size_t frameCount = 0, audio_output_flags_t flags = AUDIO_OUTPUT_FLAG_NONE, callback_t cbf = NULL, void* user = NULL, - int notificationFrames = 0, - int sessionId = 0, + uint32_t notificationFrames = 0, + int sessionId = AUDIO_SESSION_ALLOCATE, transfer_type transferType = TRANSFER_DEFAULT, const audio_offload_info_t *offloadInfo = NULL, - int uid = -1); + int uid = -1, + pid_t pid = -1); /* Creates an audio track and registers it with AudioFlinger. * With this constructor, the track is configured for static buffer mode. @@ -209,11 +208,12 @@ public: audio_output_flags_t flags = AUDIO_OUTPUT_FLAG_NONE, callback_t cbf = NULL, void* user = NULL, - int notificationFrames = 0, - int sessionId = 0, + uint32_t notificationFrames = 0, + int sessionId = AUDIO_SESSION_ALLOCATE, transfer_type transferType = TRANSFER_DEFAULT, const audio_offload_info_t *offloadInfo = NULL, - int uid = -1); + int uid = -1, + pid_t pid = -1); /* Terminates the AudioTrack and unregisters it from AudioFlinger. * Also destroys all resources associated with the AudioTrack. @@ -241,17 +241,18 @@ public: uint32_t sampleRate, audio_format_t format, audio_channel_mask_t channelMask, - int frameCount = 0, + size_t frameCount = 0, audio_output_flags_t flags = AUDIO_OUTPUT_FLAG_NONE, callback_t cbf = NULL, void* user = NULL, - int notificationFrames = 0, + uint32_t notificationFrames = 0, const sp<IMemory>& sharedBuffer = 0, bool threadCanCallJava = false, - int sessionId = 0, + int sessionId = AUDIO_SESSION_ALLOCATE, transfer_type transferType = TRANSFER_DEFAULT, const audio_offload_info_t *offloadInfo = NULL, - int uid = -1); + int uid = -1, + pid_t pid = -1); /* Result of constructing the AudioTrack. This must be checked for successful initialization * before using any AudioTrack API (except for set()), because using @@ -279,7 +280,7 @@ public: size_t frameSize() const { return mFrameSize; } uint32_t channelCount() const { return mChannelCount; } - uint32_t frameCount() const { return mFrameCount; } + size_t frameCount() const { return mFrameCount; } /* Return the static buffer specified in constructor or set(), or 0 for streaming mode */ sp<IMemory> sharedBuffer() const { return mSharedBuffer; } @@ -336,7 +337,7 @@ public: */ status_t setSampleRate(uint32_t sampleRate); - /* Return current source sample rate in Hz, or 0 if unknown */ + /* Return current source sample rate in Hz */ uint32_t getSampleRate() const; /* Enables looping and sets the start and end points of looping. @@ -361,7 +362,7 @@ public: /* Sets marker position. When playback reaches the number of frames specified, a callback with * event type EVENT_MARKER is called. Calling setMarkerPosition with marker == 0 cancels marker * notification callback. To set a marker at a position which would compute as 0, - * a workaround is to the set the marker at a nearby position such as ~0 or 1. + * a workaround is to set the marker at a nearby position such as ~0 or 1. * If the AudioTrack has been opened with no callback function associated, the operation will * fail. * @@ -450,9 +451,10 @@ public: * none. * * Returned value: - * handle on audio hardware output + * handle on audio hardware output, or AUDIO_IO_HANDLE_NONE if the + * track needed to be re-created but that failed */ - audio_io_handle_t getOutput(); + audio_io_handle_t getOutput() const; /* Returns the unique session ID associated with this track. * @@ -528,15 +530,6 @@ private: struct timespec *elapsed = NULL, size_t *nonContig = NULL); public: -//EL_FIXME to be reconciled with new obtainBuffer() return codes and control block proxy -// enum { -// NO_MORE_BUFFERS = 0x80000001, // same name in AudioFlinger.h, ok to be different value -// TEAR_DOWN = 0x80000002, -// STOPPED = 1, -// STREAM_END_WAIT, -// STREAM_END -// }; - /* Release a filled buffer of "audioBuffer->frameCount" frames for AudioFlinger to process. */ // FIXME make private when obtainBuffer() for TRANSFER_OBTAIN is removed void releaseBuffer(Buffer* audioBuffer); @@ -551,8 +544,11 @@ public: * WOULD_BLOCK when obtainBuffer() returns same, or * AudioTrack was stopped during the write * or any other error code returned by IAudioTrack::start() or restoreTrack_l(). + * Default behavior is to only return until all data has been transferred. Set 'blocking' to + * false for the method to return immediately without waiting to try multiple times to write + * the full content of the buffer. */ - ssize_t write(const void* buffer, size_t size); + ssize_t write(const void* buffer, size_t size, bool blocking = true); /* * Dumps the state of an audio track. @@ -566,7 +562,7 @@ public: uint32_t getUnderrunFrames() const; /* Get the flags */ - audio_output_flags_t getFlags() const { return mFlags; } + audio_output_flags_t getFlags() const { AutoMutex _l(mLock); return mFlags; } /* Set parameters - only possible when using direct output */ status_t setParameters(const String8& keyValuePairs); @@ -626,53 +622,50 @@ protected: // NS_INACTIVE inactive so don't run again until re-started // NS_NEVER never again static const nsecs_t NS_WHENEVER = -1, NS_INACTIVE = -2, NS_NEVER = -3; - nsecs_t processAudioBuffer(const sp<AudioTrackThread>& thread); - status_t processStreamEnd(int32_t waitCount); + nsecs_t processAudioBuffer(); + bool isOffloaded() const; // caller must hold lock on mLock for all _l methods - status_t createTrack_l(audio_stream_type_t streamType, - uint32_t sampleRate, - audio_format_t format, - size_t frameCount, - audio_output_flags_t flags, - const sp<IMemory>& sharedBuffer, - audio_io_handle_t output, - size_t epoch); + status_t createTrack_l(size_t epoch); // can only be called when mState != STATE_ACTIVE void flush_l(); void setLoop_l(uint32_t loopStart, uint32_t loopEnd, int loopCount); - audio_io_handle_t getOutput_l(); // FIXME enum is faster than strcmp() for parameter 'from' status_t restoreTrack_l(const char *from); - bool isOffloaded() const + bool isOffloaded_l() const { return (mFlags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) != 0; } - // Next 3 fields may be changed if IAudioTrack is re-created, but always != 0 + // Next 4 fields may be changed if IAudioTrack is re-created, but always != 0 sp<IAudioTrack> mAudioTrack; sp<IMemory> mCblkMemory; audio_track_cblk_t* mCblk; // re-load after mLock.unlock() + audio_io_handle_t mOutput; // returned by AudioSystem::getOutput() sp<AudioTrackThread> mAudioTrackThread; + float mVolume[2]; float mSendLevel; mutable uint32_t mSampleRate; // mutable because getSampleRate() can update it. - size_t mFrameCount; // corresponds to current IAudioTrack - size_t mReqFrameCount; // frame count to request the next time a new - // IAudioTrack is needed - + size_t mFrameCount; // corresponds to current IAudioTrack, value is + // reported back by AudioFlinger to the client + size_t mReqFrameCount; // frame count to request the first or next time + // a new IAudioTrack is needed, non-decreasing // constant after constructor or set() audio_format_t mFormat; // as requested by client, not forced to 16-bit audio_stream_type_t mStreamType; uint32_t mChannelCount; audio_channel_mask_t mChannelMask; + sp<IMemory> mSharedBuffer; transfer_type mTransfer; + audio_offload_info_t mOffloadInfoCopy; + const audio_offload_info_t* mOffloadInfo; // mFrameSize is equal to mFrameSizeAF for non-PCM or 16-bit PCM data. For 8-bit PCM data, it's // twice as large as mFrameSize because data is expanded to 16-bit before it's stored in buffer. @@ -705,21 +698,25 @@ protected: uint32_t mNotificationFramesAct; // actual number of frames between each // notification callback, // at initial source sample rate - bool mRefreshRemaining; // processAudioBuffer() should refresh next 2 + bool mRefreshRemaining; // processAudioBuffer() should refresh + // mRemainingFrames and mRetryOnPartialBuffer // These are private to processAudioBuffer(), and are not protected by a lock uint32_t mRemainingFrames; // number of frames to request in obtainBuffer() bool mRetryOnPartialBuffer; // sleep and retry after partial obtainBuffer() uint32_t mObservedSequence; // last observed value of mSequence - sp<IMemory> mSharedBuffer; uint32_t mLoopPeriod; // in frames, zero means looping is disabled + uint32_t mMarkerPosition; // in wrapping (overflow) frame units bool mMarkerReached; uint32_t mNewPosition; // in frames uint32_t mUpdatePeriod; // in frames, zero means no EVENT_NEW_POS audio_output_flags_t mFlags; + // const after set(), except for bits AUDIO_OUTPUT_FLAG_FAST and AUDIO_OUTPUT_FLAG_OFFLOAD. + // mLock must be held to read or write those bits reliably. + int mSessionId; int mAuxEffectId; @@ -739,7 +736,6 @@ protected: sp<AudioTrackClientProxy> mProxy; // primary owner of the memory bool mInUnderrun; // whether track is currently in underrun state - String8 mName; // server's name for this IAudioTrack uint32_t mPausedPosition; private: @@ -754,8 +750,8 @@ private: sp<DeathNotifier> mDeathNotifier; uint32_t mSequence; // incremented for each new IAudioTrack attempt - audio_io_handle_t mOutput; // cached output io handle int mClientUid; + pid_t mClientPid; }; class TimedAudioTrack : public AudioTrack diff --git a/include/media/IAudioFlinger.h b/include/media/IAudioFlinger.h index 282f275..9101f06 100644 --- a/include/media/IAudioFlinger.h +++ b/include/media/IAudioFlinger.h @@ -64,25 +64,27 @@ public: uint32_t sampleRate, audio_format_t format, audio_channel_mask_t channelMask, - size_t frameCount, + size_t *pFrameCount, track_flags_t *flags, const sp<IMemory>& sharedBuffer, + // On successful return, AudioFlinger takes over the handle + // reference and will release it when the track is destroyed. + // However on failure, the client is responsible for release. audio_io_handle_t output, pid_t tid, // -1 means unused, otherwise must be valid non-0 int *sessionId, - // input: ignored - // output: server's description of IAudioTrack for display in logs. - // Don't attempt to parse, as the format could change. - String8& name, int clientUid, status_t *status) = 0; virtual sp<IAudioRecord> openRecord( + // On successful return, AudioFlinger takes over the handle + // reference and will release it when the track is destroyed. + // However on failure, the client is responsible for release. audio_io_handle_t input, uint32_t sampleRate, audio_format_t format, audio_channel_mask_t channelMask, - size_t frameCount, + size_t *pFrameCount, track_flags_t *flags, pid_t tid, // -1 means unused, otherwise must be valid non-0 int *sessionId, @@ -163,7 +165,7 @@ public: audio_channel_mask_t *pChannelMask) = 0; virtual status_t closeInput(audio_io_handle_t input) = 0; - virtual status_t setStreamOutput(audio_stream_type_t stream, audio_io_handle_t output) = 0; + virtual status_t invalidateStream(audio_stream_type_t stream) = 0; virtual status_t setVoiceVolume(float volume) = 0; @@ -174,8 +176,8 @@ public: virtual int newAudioSessionId() = 0; - virtual void acquireAudioSessionId(int audioSession) = 0; - virtual void releaseAudioSessionId(int audioSession) = 0; + virtual void acquireAudioSessionId(int audioSession, pid_t pid) = 0; + virtual void releaseAudioSessionId(int audioSession, pid_t pid) = 0; virtual status_t queryNumberEffects(uint32_t *numEffects) const = 0; @@ -188,6 +190,7 @@ public: effect_descriptor_t *pDesc, const sp<IEffectClient>& client, int32_t priority, + // AudioFlinger doesn't take over handle reference from client audio_io_handle_t output, int sessionId, status_t *status, diff --git a/include/media/IMediaHTTPConnection.h b/include/media/IMediaHTTPConnection.h new file mode 100644 index 0000000..2a63eb7 --- /dev/null +++ b/include/media/IMediaHTTPConnection.h @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2013 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 I_MEDIA_HTTP_CONNECTION_H_ + +#define I_MEDIA_HTTP_CONNECTION_H_ + +#include <binder/IInterface.h> +#include <media/stagefright/foundation/ABase.h> +#include <utils/KeyedVector.h> + +namespace android { + +struct IMediaHTTPConnection; + +/** MUST stay in sync with IMediaHTTPConnection.aidl */ + +struct IMediaHTTPConnection : public IInterface { + DECLARE_META_INTERFACE(MediaHTTPConnection); + + virtual bool connect( + const char *uri, const KeyedVector<String8, String8> *headers) = 0; + + virtual void disconnect() = 0; + virtual ssize_t readAt(off64_t offset, void *data, size_t size) = 0; + virtual off64_t getSize() = 0; + virtual status_t getMIMEType(String8 *mimeType) = 0; + virtual status_t getUri(String8 *uri) = 0; + +private: + DISALLOW_EVIL_CONSTRUCTORS(IMediaHTTPConnection); +}; + +} // namespace android + +#endif // I_MEDIA_HTTP_CONNECTION_H_ diff --git a/include/media/IMediaHTTPService.h b/include/media/IMediaHTTPService.h new file mode 100644 index 0000000..f66d6c8 --- /dev/null +++ b/include/media/IMediaHTTPService.h @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2013 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 I_MEDIA_HTTP_SERVICE_H_ + +#define I_MEDIA_HTTP_SERVICE_H_ + +#include <binder/IInterface.h> +#include <media/stagefright/foundation/ABase.h> + +namespace android { + +struct IMediaHTTPConnection; + +/** MUST stay in sync with IMediaHTTPService.aidl */ + +struct IMediaHTTPService : public IInterface { + DECLARE_META_INTERFACE(MediaHTTPService); + + virtual sp<IMediaHTTPConnection> makeHTTPConnection() = 0; + +private: + DISALLOW_EVIL_CONSTRUCTORS(IMediaHTTPService); +}; + +} // namespace android + +#endif // I_MEDIA_HTTP_SERVICE_H_ diff --git a/include/media/IMediaMetadataRetriever.h b/include/media/IMediaMetadataRetriever.h index 6dbb2d7..2529800 100644 --- a/include/media/IMediaMetadataRetriever.h +++ b/include/media/IMediaMetadataRetriever.h @@ -26,6 +26,8 @@ namespace android { +struct IMediaHTTPService; + class IMediaMetadataRetriever: public IInterface { public: @@ -33,6 +35,7 @@ public: virtual void disconnect() = 0; virtual status_t setDataSource( + const sp<IMediaHTTPService> &httpService, const char *srcUrl, const KeyedVector<String8, String8> *headers = NULL) = 0; diff --git a/include/media/IMediaPlayer.h b/include/media/IMediaPlayer.h index 0cbd269..db62cd5 100644 --- a/include/media/IMediaPlayer.h +++ b/include/media/IMediaPlayer.h @@ -33,6 +33,7 @@ class Parcel; class Surface; class IStreamSource; class IGraphicBufferProducer; +struct IMediaHTTPService; class IMediaPlayer: public IInterface { @@ -41,8 +42,11 @@ public: virtual void disconnect() = 0; - virtual status_t setDataSource(const char *url, - const KeyedVector<String8, String8>* headers) = 0; + virtual status_t setDataSource( + const sp<IMediaHTTPService> &httpService, + const char *url, + const KeyedVector<String8, String8>* headers) = 0; + virtual status_t setDataSource(int fd, int64_t offset, int64_t length) = 0; virtual status_t setDataSource(const sp<IStreamSource>& source) = 0; virtual status_t setVideoSurfaceTexture( diff --git a/include/media/IMediaPlayerService.h b/include/media/IMediaPlayerService.h index 2998b37..5b45376 100644 --- a/include/media/IMediaPlayerService.h +++ b/include/media/IMediaPlayerService.h @@ -34,6 +34,7 @@ namespace android { struct ICrypto; struct IDrm; struct IHDCP; +struct IMediaHTTPService; class IMediaRecorder; class IOMX; class IRemoteDisplay; @@ -49,9 +50,14 @@ public: virtual sp<IMediaMetadataRetriever> createMetadataRetriever() = 0; virtual sp<IMediaPlayer> create(const sp<IMediaPlayerClient>& client, int audioSessionId = 0) = 0; - virtual status_t decode(const char* url, uint32_t *pSampleRate, int* pNumChannels, - audio_format_t* pFormat, - const sp<IMemoryHeap>& heap, size_t *pSize) = 0; + virtual status_t decode( + const sp<IMediaHTTPService> &httpService, + const char* url, + uint32_t *pSampleRate, + int* pNumChannels, + audio_format_t* pFormat, + const sp<IMemoryHeap>& heap, size_t *pSize) = 0; + virtual status_t decode(int fd, int64_t offset, int64_t length, uint32_t *pSampleRate, int* pNumChannels, audio_format_t* pFormat, const sp<IMemoryHeap>& heap, size_t *pSize) = 0; @@ -93,9 +99,6 @@ public: virtual void addBatteryData(uint32_t params) = 0; virtual status_t pullBatteryData(Parcel* reply) = 0; - - virtual status_t updateProxyConfig( - const char *host, int32_t port, const char *exclusionList) = 0; }; // ---------------------------------------------------------------------------- diff --git a/include/media/IOMX.h b/include/media/IOMX.h index 6643736..f6f9e7a 100644 --- a/include/media/IOMX.h +++ b/include/media/IOMX.h @@ -143,6 +143,8 @@ public: INTERNAL_OPTION_SUSPEND, // data is a bool INTERNAL_OPTION_REPEAT_PREVIOUS_FRAME_DELAY, // data is an int64_t INTERNAL_OPTION_MAX_TIMESTAMP_GAP, // data is int64_t + INTERNAL_OPTION_START_TIME, // data is an int64_t + INTERNAL_OPTION_TIME_LAPSE, // data is an int64_t[2] }; virtual status_t setInternalOption( node_id node, diff --git a/include/media/MediaMetadataRetrieverInterface.h b/include/media/MediaMetadataRetrieverInterface.h index ecc3b65..bb6b97b 100644 --- a/include/media/MediaMetadataRetrieverInterface.h +++ b/include/media/MediaMetadataRetrieverInterface.h @@ -24,6 +24,8 @@ namespace android { +struct IMediaHTTPService; + // Abstract base class class MediaMetadataRetrieverBase : public RefBase { @@ -32,6 +34,7 @@ public: virtual ~MediaMetadataRetrieverBase() {} virtual status_t setDataSource( + const sp<IMediaHTTPService> &httpService, const char *url, const KeyedVector<String8, String8> *headers = NULL) = 0; diff --git a/include/media/MediaPlayerInterface.h b/include/media/MediaPlayerInterface.h index 26d8729..87717da 100644 --- a/include/media/MediaPlayerInterface.h +++ b/include/media/MediaPlayerInterface.h @@ -137,6 +137,7 @@ public: } virtual status_t setDataSource( + const sp<IMediaHTTPService> &httpService, const char *url, const KeyedVector<String8, String8> *headers = NULL) = 0; @@ -213,11 +214,6 @@ public: return INVALID_OPERATION; } - virtual status_t updateProxyConfig( - const char *host, int32_t port, const char *exclusionList) { - return INVALID_OPERATION; - } - private: friend class MediaPlayerService; diff --git a/include/media/mediametadataretriever.h b/include/media/mediametadataretriever.h index 0df77c1..b35cf32 100644 --- a/include/media/mediametadataretriever.h +++ b/include/media/mediametadataretriever.h @@ -25,6 +25,7 @@ namespace android { +struct IMediaHTTPService; class IMediaPlayerService; class IMediaMetadataRetriever; @@ -68,6 +69,7 @@ public: void disconnect(); status_t setDataSource( + const sp<IMediaHTTPService> &httpService, const char *dataSourceUrl, const KeyedVector<String8, String8> *headers = NULL); diff --git a/include/media/mediaplayer.h b/include/media/mediaplayer.h index 4c05fc3..3ca3095 100644 --- a/include/media/mediaplayer.h +++ b/include/media/mediaplayer.h @@ -189,6 +189,8 @@ public: virtual void notify(int msg, int ext1, int ext2, const Parcel *obj) = 0; }; +struct IMediaHTTPService; + class MediaPlayer : public BnMediaPlayerClient, public virtual IMediaDeathNotifier { @@ -199,6 +201,7 @@ public: void disconnect(); status_t setDataSource( + const sp<IMediaHTTPService> &httpService, const char *url, const KeyedVector<String8, String8> *headers); @@ -220,13 +223,19 @@ public: status_t getDuration(int *msec); status_t reset(); status_t setAudioStreamType(audio_stream_type_t type); + status_t getAudioStreamType(audio_stream_type_t *type); status_t setLooping(int loop); bool isLooping(); status_t setVolume(float leftVolume, float rightVolume); void notify(int msg, int ext1, int ext2, const Parcel *obj = NULL); - static status_t decode(const char* url, uint32_t *pSampleRate, int* pNumChannels, - audio_format_t* pFormat, - const sp<IMemoryHeap>& heap, size_t *pSize); + static status_t decode( + const sp<IMediaHTTPService> &httpService, + const char* url, + uint32_t *pSampleRate, + int* pNumChannels, + audio_format_t* pFormat, + const sp<IMemoryHeap>& heap, + size_t *pSize); static status_t decode(int fd, int64_t offset, int64_t length, uint32_t *pSampleRate, int* pNumChannels, audio_format_t* pFormat, const sp<IMemoryHeap>& heap, size_t *pSize); @@ -242,9 +251,6 @@ public: status_t setRetransmitEndpoint(const char* addrString, uint16_t port); status_t setNextMediaPlayer(const sp<MediaPlayer>& player); - status_t updateProxyConfig( - const char *host, int32_t port, const char *exclusionList); - private: void clear_l(); status_t seekTo_l(int msec); diff --git a/include/media/mediarecorder.h b/include/media/mediarecorder.h index 88a42a0..142cb90 100644 --- a/include/media/mediarecorder.h +++ b/include/media/mediarecorder.h @@ -39,7 +39,7 @@ typedef void (*media_completion_f)(status_t status, void *cookie); enum video_source { VIDEO_SOURCE_DEFAULT = 0, VIDEO_SOURCE_CAMERA = 1, - VIDEO_SOURCE_GRALLOC_BUFFER = 2, + VIDEO_SOURCE_SURFACE = 2, VIDEO_SOURCE_LIST_END // must be last - used to validate audio source type }; diff --git a/include/media/mediascanner.h b/include/media/mediascanner.h index a73403b..4537679 100644 --- a/include/media/mediascanner.h +++ b/include/media/mediascanner.h @@ -21,6 +21,7 @@ #include <utils/threads.h> #include <utils/List.h> #include <utils/Errors.h> +#include <utils/String8.h> #include <pthread.h> struct dirent; @@ -29,6 +30,7 @@ namespace android { class MediaScannerClient; class StringArray; +class CharacterEncodingDetector; enum MediaScanResult { // This file or directory was scanned successfully. @@ -94,15 +96,9 @@ public: virtual status_t setMimeType(const char* mimeType) = 0; protected: - void convertValues(uint32_t encoding); - -protected: - // cached name and value strings, for native encoding support. - StringArray* mNames; - StringArray* mValues; - - // default encoding based on MediaScanner::mLocale string - uint32_t mLocaleEncoding; + // default encoding from MediaScanner::mLocale + String8 mLocale; + CharacterEncodingDetector *mEncodingDetector; }; }; // namespace android diff --git a/include/media/nbaio/AudioBufferProviderSource.h b/include/media/nbaio/AudioBufferProviderSource.h index 2c4aaff..b16e20a 100644 --- a/include/media/nbaio/AudioBufferProviderSource.h +++ b/include/media/nbaio/AudioBufferProviderSource.h @@ -27,7 +27,7 @@ namespace android { class AudioBufferProviderSource : public NBAIO_Source { public: - AudioBufferProviderSource(AudioBufferProvider *provider, NBAIO_Format format); + AudioBufferProviderSource(AudioBufferProvider *provider, const NBAIO_Format& format); virtual ~AudioBufferProviderSource(); // NBAIO_Port interface diff --git a/include/media/nbaio/AudioStreamInSource.h b/include/media/nbaio/AudioStreamInSource.h index 07d8c89..eaea63c 100644 --- a/include/media/nbaio/AudioStreamInSource.h +++ b/include/media/nbaio/AudioStreamInSource.h @@ -43,7 +43,7 @@ public: // This is an over-estimate, and could dupe the caller into making a blocking read() // FIXME Use an audio HAL API to query the buffer filling status when it's available. - virtual ssize_t availableToRead() { return mStreamBufferSizeBytes >> mBitShift; } + virtual ssize_t availableToRead() { return mStreamBufferSizeBytes / mFrameSize; } virtual ssize_t read(void *buffer, size_t count); diff --git a/include/media/nbaio/AudioStreamOutSink.h b/include/media/nbaio/AudioStreamOutSink.h index 7948d40..9949b88 100644 --- a/include/media/nbaio/AudioStreamOutSink.h +++ b/include/media/nbaio/AudioStreamOutSink.h @@ -43,7 +43,7 @@ public: // This is an over-estimate, and could dupe the caller into making a blocking write() // FIXME Use an audio HAL API to query the buffer emptying status when it's available. - virtual ssize_t availableToWrite() const { return mStreamBufferSizeBytes >> mBitShift; } + virtual ssize_t availableToWrite() const { return mStreamBufferSizeBytes / mFrameSize; } virtual ssize_t write(const void *buffer, size_t count); diff --git a/include/media/nbaio/MonoPipe.h b/include/media/nbaio/MonoPipe.h index d3802fe..b09b35f 100644 --- a/include/media/nbaio/MonoPipe.h +++ b/include/media/nbaio/MonoPipe.h @@ -41,7 +41,7 @@ public: // Note: whatever shares this object with another thread needs to do so in an SMP-safe way (like // creating it the object before creating the other thread, or storing the object with a // release_store). Otherwise the other thread could see a partially-constructed object. - MonoPipe(size_t reqFrames, NBAIO_Format format, bool writeCanBlock = false); + MonoPipe(size_t reqFrames, const NBAIO_Format& format, bool writeCanBlock = false); virtual ~MonoPipe(); // NBAIO_Port interface diff --git a/include/media/nbaio/NBAIO.h b/include/media/nbaio/NBAIO.h index 1da0c73..be0c15b 100644 --- a/include/media/nbaio/NBAIO.h +++ b/include/media/nbaio/NBAIO.h @@ -29,6 +29,7 @@ #include <utils/Errors.h> #include <utils/RefBase.h> #include <media/AudioTimestamp.h> +#include <system/audio.h> namespace android { @@ -52,31 +53,41 @@ enum { // the combinations that are actually needed within AudioFlinger. If the list of combinations grows // too large, then this decision should be re-visited. // Sample rate and channel count are explicit, PCM interleaved 16-bit is assumed. -typedef unsigned NBAIO_Format; -enum { - Format_Invalid +struct NBAIO_Format { +// FIXME make this a class, and change Format_... global methods to class methods +//private: + unsigned mSampleRate; + unsigned mChannelCount; + audio_format_t mFormat; + size_t mFrameSize; }; -// Return the frame size of an NBAIO_Format in bytes -size_t Format_frameSize(NBAIO_Format format); +extern const NBAIO_Format Format_Invalid; -// Return the frame size of an NBAIO_Format as a bit shift -size_t Format_frameBitShift(NBAIO_Format format); +// Return the frame size of an NBAIO_Format in bytes +size_t Format_frameSize(const NBAIO_Format& format); // Convert a sample rate in Hz and channel count to an NBAIO_Format -NBAIO_Format Format_from_SR_C(unsigned sampleRate, unsigned channelCount); +// FIXME rename +NBAIO_Format Format_from_SR_C(unsigned sampleRate, unsigned channelCount, audio_format_t format); // Return the sample rate in Hz of an NBAIO_Format -unsigned Format_sampleRate(NBAIO_Format format); +unsigned Format_sampleRate(const NBAIO_Format& format); // Return the channel count of an NBAIO_Format -unsigned Format_channelCount(NBAIO_Format format); +unsigned Format_channelCount(const NBAIO_Format& format); // Callbacks used by NBAIO_Sink::writeVia() and NBAIO_Source::readVia() below. typedef ssize_t (*writeVia_t)(void *user, void *buffer, size_t count); typedef ssize_t (*readVia_t)(void *user, const void *buffer, size_t count, int64_t readPTS); +// Check whether an NBAIO_Format is valid +bool Format_isValid(const NBAIO_Format& format); + +// Compare two NBAIO_Format values +bool Format_isEqual(const NBAIO_Format& format1, const NBAIO_Format& format2); + // Abstract class (interface) representing a data port. class NBAIO_Port : public RefBase { @@ -115,15 +126,15 @@ public: virtual NBAIO_Format format() const { return mNegotiated ? mFormat : Format_Invalid; } protected: - NBAIO_Port(NBAIO_Format format) : mNegotiated(false), mFormat(format), - mBitShift(Format_frameBitShift(format)) { } + NBAIO_Port(const NBAIO_Format& format) : mNegotiated(false), mFormat(format), + mFrameSize(Format_frameSize(format)) { } virtual ~NBAIO_Port() { } // Implementations are free to ignore these if they don't need them bool mNegotiated; // mNegotiated implies (mFormat != Format_Invalid) NBAIO_Format mFormat; // (mFormat != Format_Invalid) does not imply mNegotiated - size_t mBitShift; // assign in parallel with any assignment to mFormat + size_t mFrameSize; // assign in parallel with any assignment to mFormat }; // Abstract class (interface) representing a non-blocking data sink, for use by a data provider. @@ -220,7 +231,7 @@ public: virtual status_t getTimestamp(AudioTimestamp& timestamp) { return INVALID_OPERATION; } protected: - NBAIO_Sink(NBAIO_Format format = Format_Invalid) : NBAIO_Port(format), mFramesWritten(0) { } + NBAIO_Sink(const NBAIO_Format& format = Format_Invalid) : NBAIO_Port(format), mFramesWritten(0) { } virtual ~NBAIO_Sink() { } // Implementations are free to ignore these if they don't need them @@ -311,7 +322,7 @@ public: virtual void onTimestamp(const AudioTimestamp& timestamp) { } protected: - NBAIO_Source(NBAIO_Format format = Format_Invalid) : NBAIO_Port(format), mFramesRead(0) { } + NBAIO_Source(const NBAIO_Format& format = Format_Invalid) : NBAIO_Port(format), mFramesRead(0) { } virtual ~NBAIO_Source() { } // Implementations are free to ignore these if they don't need them diff --git a/include/media/nbaio/Pipe.h b/include/media/nbaio/Pipe.h index 79a4eee..c784129 100644 --- a/include/media/nbaio/Pipe.h +++ b/include/media/nbaio/Pipe.h @@ -30,7 +30,7 @@ class Pipe : public NBAIO_Sink { public: // maxFrames will be rounded up to a power of 2, and all slots are available. Must be >= 2. - Pipe(size_t maxFrames, NBAIO_Format format); + Pipe(size_t maxFrames, const NBAIO_Format& format); virtual ~Pipe(); // NBAIO_Port interface diff --git a/include/media/nbaio/SourceAudioBufferProvider.h b/include/media/nbaio/SourceAudioBufferProvider.h index cdfb6fe..daf6bc3 100644 --- a/include/media/nbaio/SourceAudioBufferProvider.h +++ b/include/media/nbaio/SourceAudioBufferProvider.h @@ -41,7 +41,7 @@ public: private: const sp<NBAIO_Source> mSource; // the wrapped source - /*const*/ size_t mFrameBitShift; // log2(frame size in bytes) + /*const*/ size_t mFrameSize; // frame size in bytes void* mAllocated; // pointer to base of allocated memory size_t mSize; // size of mAllocated in frames size_t mOffset; // frame offset within mAllocated of valid data diff --git a/include/media/stagefright/ACodec.h b/include/media/stagefright/ACodec.h index 7ba5acc..8ec7f1c 100644 --- a/include/media/stagefright/ACodec.h +++ b/include/media/stagefright/ACodec.h @@ -67,8 +67,6 @@ struct ACodec : public AHierarchicalStateMachine { void signalRequestIDRFrame(); - bool isConfiguredForAdaptivePlayback() { return mIsConfiguredForAdaptivePlayback; } - struct PortDescription : public RefBase { size_t countBuffers(); IOMX::buffer_id bufferIDAt(size_t index) const; @@ -178,6 +176,8 @@ private: sp<MemoryDealer> mDealer[2]; sp<ANativeWindow> mNativeWindow; + sp<AMessage> mInputFormat; + sp<AMessage> mOutputFormat; Vector<BufferInfo> mBuffers[2]; bool mPortEOS[2]; @@ -189,7 +189,7 @@ private: bool mIsEncoder; bool mUseMetadataOnEncoderOutput; bool mShutdownInProgress; - bool mIsConfiguredForAdaptivePlayback; + bool mExplicitShutdown; // If "mKeepComponentAllocated" we only transition back to Loaded state // and do not release the component instance. @@ -203,10 +203,16 @@ private: unsigned mDequeueCounter; bool mStoreMetaDataInOutputBuffers; int32_t mMetaDataBuffersToSubmit; + size_t mNumUndequeuedBuffers; int64_t mRepeatFrameDelayUs; int64_t mMaxPtsGapUs; + int64_t mTimePerFrameUs; + int64_t mTimePerCaptureUs; + + bool mCreateInputBuffersSuspended; + status_t setCyclicIntraMacroblockRefresh(const sp<AMessage> &msg, int32_t mode); status_t allocateBuffersOnPort(OMX_U32 portIndex); status_t freeBuffersOnPort(OMX_U32 portIndex); @@ -300,6 +306,7 @@ private: void processDeferredMessages(); void sendFormatChange(const sp<AMessage> &reply); + status_t getPortFormat(OMX_U32 portIndex, sp<AMessage> ¬ify); void signalError( OMX_ERRORTYPE error = OMX_ErrorUndefined, diff --git a/include/media/stagefright/CameraSource.h b/include/media/stagefright/CameraSource.h index a829916..dd0a106 100644 --- a/include/media/stagefright/CameraSource.h +++ b/include/media/stagefright/CameraSource.h @@ -172,7 +172,7 @@ protected: const sp<IGraphicBufferProducer>& surface, bool storeMetaDataInVideoBuffers); - virtual void startCameraRecording(); + virtual status_t startCameraRecording(); virtual void releaseRecordingFrame(const sp<IMemory>& frame); // Returns true if need to skip the current frame. @@ -185,6 +185,8 @@ protected: virtual void dataCallbackTimestamp(int64_t timestampUs, int32_t msgType, const sp<IMemory> &data); + void releaseCamera(); + private: friend class CameraSourceListener; @@ -233,7 +235,6 @@ private: int32_t frameRate); void stopCameraRecording(); - void releaseCamera(); status_t reset(); CameraSource(const CameraSource &); diff --git a/include/media/stagefright/DataSource.h b/include/media/stagefright/DataSource.h index 157b1aa..f8787dd 100644 --- a/include/media/stagefright/DataSource.h +++ b/include/media/stagefright/DataSource.h @@ -31,6 +31,7 @@ namespace android { struct AMessage; +struct IMediaHTTPService; class String8; class DataSource : public RefBase { @@ -43,6 +44,7 @@ public: }; static sp<DataSource> CreateFromURI( + const sp<IMediaHTTPService> &httpService, const char *uri, const KeyedVector<String8, String8> *headers = NULL); diff --git a/include/media/stagefright/DataURISource.h b/include/media/stagefright/DataURISource.h new file mode 100644 index 0000000..693562e --- /dev/null +++ b/include/media/stagefright/DataURISource.h @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2014 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 DATA_URI_SOURCE_H_ + +#define DATA_URI_SOURCE_H_ + +#include <media/stagefright/DataSource.h> +#include <media/stagefright/foundation/ABase.h> + +namespace android { + +struct ABuffer; + +struct DataURISource : public DataSource { + static sp<DataURISource> Create(const char *uri); + + virtual status_t initCheck() const; + virtual ssize_t readAt(off64_t offset, void *data, size_t size); + virtual status_t getSize(off64_t *size); + +protected: + virtual ~DataURISource(); + +private: + sp<ABuffer> mBuffer; + + DataURISource(const sp<ABuffer> &buffer); + + DISALLOW_EVIL_CONSTRUCTORS(DataURISource); +}; + +} // namespace android + +#endif // DATA_URI_SOURCE_H_ + diff --git a/include/media/stagefright/FileSource.h b/include/media/stagefright/FileSource.h index be152e7..a981d1c 100644 --- a/include/media/stagefright/FileSource.h +++ b/include/media/stagefright/FileSource.h @@ -30,6 +30,7 @@ namespace android { class FileSource : public DataSource { public: FileSource(const char *filename); + // FileSource takes ownership and will close the fd FileSource(int fd, int64_t offset, int64_t length); virtual status_t initCheck() const; diff --git a/include/media/stagefright/MediaCodec.h b/include/media/stagefright/MediaCodec.h index 76aa503..276543b 100644 --- a/include/media/stagefright/MediaCodec.h +++ b/include/media/stagefright/MediaCodec.h @@ -106,6 +106,7 @@ struct MediaCodec : public AHandler { status_t signalEndOfInputStream(); status_t getOutputFormat(sp<AMessage> *format) const; + status_t getInputFormat(sp<AMessage> *format) const; status_t getInputBuffers(Vector<sp<ABuffer> > *buffers) const; status_t getOutputBuffers(Vector<sp<ABuffer> > *buffers) const; @@ -159,6 +160,7 @@ private: kWhatGetBuffers = 'getB', kWhatFlush = 'flus', kWhatGetOutputFormat = 'getO', + kWhatGetInputFormat = 'getI', kWhatDequeueInputTimedOut = 'dITO', kWhatDequeueOutputTimedOut = 'dOTO', kWhatCodecNotify = 'codc', @@ -199,6 +201,7 @@ private: sp<Surface> mNativeWindow; SoftwareRenderer *mSoftRenderer; sp<AMessage> mOutputFormat; + sp<AMessage> mInputFormat; List<size_t> mAvailPortBuffers[2]; Vector<BufferInfo> mPortBuffers[2]; diff --git a/include/media/stagefright/MediaCodecList.h b/include/media/stagefright/MediaCodecList.h index 590623b..01a5daf 100644 --- a/include/media/stagefright/MediaCodecList.h +++ b/include/media/stagefright/MediaCodecList.h @@ -60,6 +60,7 @@ private: SECTION_DECODER, SECTION_ENCODERS, SECTION_ENCODER, + SECTION_INCLUDE, }; struct CodecInfo { @@ -73,7 +74,9 @@ private: status_t mInitCheck; Section mCurrentSection; + Vector<Section> mPastSections; int32_t mDepth; + AString mHrefBase; Vector<CodecInfo> mCodecInfos; KeyedVector<AString, size_t> mCodecQuirks; @@ -83,7 +86,8 @@ private: ~MediaCodecList(); status_t initCheck() const; - void parseXMLFile(FILE *file); + void parseXMLFile(const char *path); + void parseTopLevelXMLFile(const char *path); static void StartElementHandlerWrapper( void *me, const char *name, const char **attrs); @@ -93,6 +97,7 @@ private: void startElementHandler(const char *name, const char **attrs); void endElementHandler(const char *name); + status_t includeXMLFile(const char **attrs); status_t addMediaCodecFromAttributes(bool encoder, const char **attrs); void addMediaCodec(bool encoder, const char *name, const char *type = NULL); diff --git a/include/media/stagefright/MediaCodecSource.h b/include/media/stagefright/MediaCodecSource.h new file mode 100644 index 0000000..4b18a0b --- /dev/null +++ b/include/media/stagefright/MediaCodecSource.h @@ -0,0 +1,134 @@ +/* + * Copyright (C) 2014 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 MediaCodecSource_H_ +#define MediaCodecSource_H_ + +#include <media/stagefright/foundation/ABase.h> +#include <media/stagefright/foundation/AHandlerReflector.h> +#include <media/stagefright/MediaSource.h> + +namespace android { + +class ALooper; +class AMessage; +class IGraphicBufferProducer; +class MediaCodec; +class MetaData; + +struct MediaCodecSource : public MediaSource, + public MediaBufferObserver { + enum FlagBits { + FLAG_USE_SURFACE_INPUT = 1, + FLAG_USE_METADATA_INPUT = 2, + }; + + static sp<MediaCodecSource> Create( + const sp<ALooper> &looper, + const sp<AMessage> &format, + const sp<MediaSource> &source, + uint32_t flags = 0); + + bool isVideo() const { return mIsVideo; } + sp<IGraphicBufferProducer> getGraphicBufferProducer(); + + // MediaSource + virtual status_t start(MetaData *params = NULL); + virtual status_t stop(); + virtual status_t pause(); + virtual sp<MetaData> getFormat() { return mMeta; } + virtual status_t read( + MediaBuffer **buffer, + const ReadOptions *options = NULL); + + // MediaBufferObserver + virtual void signalBufferReturned(MediaBuffer *buffer); + + // for AHandlerReflector + void onMessageReceived(const sp<AMessage> &msg); + +protected: + virtual ~MediaCodecSource(); + +private: + struct Puller; + + enum { + kWhatPullerNotify, + kWhatEncoderActivity, + kWhatStart, + kWhatStop, + kWhatPause, + }; + + MediaCodecSource( + const sp<ALooper> &looper, + const sp<AMessage> &outputFormat, + const sp<MediaSource> &source, + uint32_t flags = 0); + + status_t onStart(MetaData *params); + status_t init(); + status_t initEncoder(); + void releaseEncoder(); + status_t feedEncoderInputBuffers(); + void scheduleDoMoreWork(); + status_t doMoreWork(); + void suspend(); + void resume(int64_t skipFramesBeforeUs = -1ll); + void signalEOS(status_t err = ERROR_END_OF_STREAM); + bool reachedEOS(); + status_t postSynchronouslyAndReturnError(const sp<AMessage> &msg); + + sp<ALooper> mLooper; + sp<ALooper> mCodecLooper; + sp<AHandlerReflector<MediaCodecSource> > mReflector; + sp<AMessage> mOutputFormat; + sp<MetaData> mMeta; + sp<Puller> mPuller; + sp<MediaCodec> mEncoder; + uint32_t mFlags; + List<uint32_t> mStopReplyIDQueue; + bool mIsVideo; + bool mStarted; + bool mStopping; + bool mDoMoreWorkPending; + bool mPullerReachedEOS; + sp<AMessage> mEncoderActivityNotify; + sp<IGraphicBufferProducer> mGraphicBufferProducer; + Vector<sp<ABuffer> > mEncoderInputBuffers; + Vector<sp<ABuffer> > mEncoderOutputBuffers; + List<MediaBuffer *> mInputBufferQueue; + List<size_t> mAvailEncoderInputIndices; + List<int64_t> mDecodingTimeQueue; // decoding time (us) for video + + // audio drift time + int64_t mFirstSampleTimeUs; + List<int64_t> mDriftTimeQueue; + + // following variables are protected by mOutputBufferLock + Mutex mOutputBufferLock; + Condition mOutputBufferCond; + List<MediaBuffer*> mOutputBufferQueue; + bool mEncodedReachedEOS; + status_t mErrorCode; + + DISALLOW_EVIL_CONSTRUCTORS(MediaCodecSource); +}; + +} // namespace android + +#endif /* MediaCodecSource_H_ */ diff --git a/include/media/stagefright/MediaDefs.h b/include/media/stagefright/MediaDefs.h index cf5beda..678d642 100644 --- a/include/media/stagefright/MediaDefs.h +++ b/include/media/stagefright/MediaDefs.h @@ -38,6 +38,7 @@ extern const char *MEDIA_MIMETYPE_AUDIO_MPEG_LAYER_II; extern const char *MEDIA_MIMETYPE_AUDIO_AAC; extern const char *MEDIA_MIMETYPE_AUDIO_QCELP; extern const char *MEDIA_MIMETYPE_AUDIO_VORBIS; +extern const char *MEDIA_MIMETYPE_AUDIO_OPUS; extern const char *MEDIA_MIMETYPE_AUDIO_G711_ALAW; extern const char *MEDIA_MIMETYPE_AUDIO_G711_MLAW; extern const char *MEDIA_MIMETYPE_AUDIO_RAW; diff --git a/include/media/stagefright/MediaHTTP.h b/include/media/stagefright/MediaHTTP.h new file mode 100644 index 0000000..006d8d8 --- /dev/null +++ b/include/media/stagefright/MediaHTTP.h @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2013 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_HTTP_H_ + +#define MEDIA_HTTP_H_ + +#include <media/stagefright/foundation/AString.h> + +#include "include/HTTPBase.h" + +namespace android { + +struct IMediaHTTPConnection; + +struct MediaHTTP : public HTTPBase { + MediaHTTP(const sp<IMediaHTTPConnection> &conn); + + virtual status_t connect( + const char *uri, + const KeyedVector<String8, String8> *headers, + off64_t offset); + + virtual void disconnect(); + + virtual status_t initCheck() const; + + virtual ssize_t readAt(off64_t offset, void *data, size_t size); + + virtual status_t getSize(off64_t *size); + + virtual uint32_t flags(); + + virtual status_t reconnectAtOffset(off64_t offset); + +protected: + virtual ~MediaHTTP(); + + virtual sp<DecryptHandle> DrmInitialization(const char* mime); + virtual void getDrmInfo(sp<DecryptHandle> &handle, DrmManagerClient **client); + virtual String8 getUri(); + virtual String8 getMIMEType() const; + +private: + status_t mInitCheck; + sp<IMediaHTTPConnection> mHTTPConnection; + + KeyedVector<String8, String8> mLastHeaders; + AString mLastURI; + + bool mCachedSizeValid; + off64_t mCachedSize; + + sp<DecryptHandle> mDecryptHandle; + DrmManagerClient *mDrmManagerClient; + + void clearDRMState_l(); + + DISALLOW_EVIL_CONSTRUCTORS(MediaHTTP); +}; + +} // namespace android + +#endif // MEDIA_HTTP_H_ diff --git a/include/media/stagefright/MediaMuxer.h b/include/media/stagefright/MediaMuxer.h index ff6a66e..bbe4303 100644 --- a/include/media/stagefright/MediaMuxer.h +++ b/include/media/stagefright/MediaMuxer.h @@ -30,7 +30,7 @@ struct MediaAdapter; struct MediaBuffer; struct MediaSource; struct MetaData; -struct MPEG4Writer; +struct MediaWriter; // MediaMuxer is used to mux multiple tracks into a video. Currently, we only // support a mp4 file as the output. @@ -44,6 +44,7 @@ public: // OutputFormat is updated. enum OutputFormat { OUTPUT_FORMAT_MPEG_4 = 0, + OUTPUT_FORMAT_WEBM = 1, OUTPUT_FORMAT_LIST_END // must be last - used to validate format type }; @@ -115,7 +116,8 @@ public: int64_t timeUs, uint32_t flags) ; private: - sp<MPEG4Writer> mWriter; + const OutputFormat mFormat; + sp<MediaWriter> mWriter; Vector< sp<MediaAdapter> > mTrackList; // Each track has its MediaAdapter. sp<MetaData> mFileMeta; // Metadata for the whole file. diff --git a/include/media/stagefright/MetaData.h b/include/media/stagefright/MetaData.h index db8216b..e862ec3 100644 --- a/include/media/stagefright/MetaData.h +++ b/include/media/stagefright/MetaData.h @@ -56,6 +56,9 @@ enum { kKeyD263 = 'd263', // raw data kKeyVorbisInfo = 'vinf', // raw data kKeyVorbisBooks = 'vboo', // raw data + kKeyOpusHeader = 'ohdr', // raw data + kKeyOpusCodecDelay = 'ocod', // uint64_t (codec delay in ns) + kKeyOpusSeekPreRoll = 'ospr', // uint64_t (seek preroll in ns) kKeyWantsNALFragments = 'NALf', kKeyIsSyncFrame = 'sync', // int32_t (bool) kKeyIsCodecConfig = 'conf', // int32_t (bool) diff --git a/include/media/stagefright/NuMediaExtractor.h b/include/media/stagefright/NuMediaExtractor.h index 5ae6f6b..402e7f8 100644 --- a/include/media/stagefright/NuMediaExtractor.h +++ b/include/media/stagefright/NuMediaExtractor.h @@ -31,6 +31,7 @@ namespace android { struct ABuffer; struct AMessage; struct DataSource; +struct IMediaHTTPService; struct MediaBuffer; struct MediaExtractor; struct MediaSource; @@ -45,6 +46,7 @@ struct NuMediaExtractor : public RefBase { NuMediaExtractor(); status_t setDataSource( + const sp<IMediaHTTPService> &httpService, const char *path, const KeyedVector<String8, String8> *headers = NULL); diff --git a/include/media/stagefright/SkipCutBuffer.h b/include/media/stagefright/SkipCutBuffer.h index 2653b53..098aa69 100644 --- a/include/media/stagefright/SkipCutBuffer.h +++ b/include/media/stagefright/SkipCutBuffer.h @@ -47,6 +47,7 @@ class SkipCutBuffer: public RefBase { private: void write(const char *src, size_t num); size_t read(char *dst, size_t num); + int32_t mSkip; int32_t mFrontPadding; int32_t mBackPadding; int32_t mWriteHead; diff --git a/include/media/stagefright/SurfaceMediaSource.h b/include/media/stagefright/SurfaceMediaSource.h index db5f947..43b75fd 100644 --- a/include/media/stagefright/SurfaceMediaSource.h +++ b/include/media/stagefright/SurfaceMediaSource.h @@ -111,7 +111,7 @@ public: // pass metadata through the buffers. Currently, it is force set to true bool isMetaDataStoredInVideoBuffers() const; - sp<BufferQueue> getBufferQueue() const { return mBufferQueue; } + sp<IGraphicBufferProducer> getProducer() const { return mProducer; } // To be called before start() status_t setMaxAcquiredBufferCount(size_t count); @@ -139,12 +139,17 @@ protected: // frames is separate than the one calling stop. virtual void onBuffersReleased(); + // SurfaceMediaSource can't handle sideband streams, so this is not expected + // to ever be called. Does nothing. + virtual void onSidebandStreamChanged(); + static bool isExternalFormat(uint32_t format); private: - // mBufferQueue is the exchange point between the producer and - // this consumer - sp<BufferQueue> mBufferQueue; + // A BufferQueue, represented by these interfaces, is the exchange point + // between the producer and this consumer + sp<IGraphicBufferProducer> mProducer; + sp<IGraphicBufferConsumer> mConsumer; struct SlotData { sp<GraphicBuffer> mGraphicBuffer; diff --git a/include/media/stagefright/Utils.h b/include/media/stagefright/Utils.h index bbad271..c85368f 100644 --- a/include/media/stagefright/Utils.h +++ b/include/media/stagefright/Utils.h @@ -60,6 +60,8 @@ status_t sendMetaDataToHal(sp<MediaPlayerBase::AudioSink>& sink, const sp<MetaDa bool canOffloadStream(const sp<MetaData>& meta, bool hasVideo, bool isStreaming, audio_stream_type_t streamType); +AString uriDebugString(const AString &uri, bool incognito = false); + } // namespace android #endif // UTILS_H_ diff --git a/include/media/stagefright/foundation/AString.h b/include/media/stagefright/foundation/AString.h index 0f8f1e1..622028e 100644 --- a/include/media/stagefright/foundation/AString.h +++ b/include/media/stagefright/foundation/AString.h @@ -22,10 +22,13 @@ namespace android { +struct String8; + struct AString { AString(); AString(const char *s); AString(const char *s, size_t size); + AString(const String8 &from); AString(const AString &from); AString(const AString &from, size_t offset, size_t n); ~AString(); diff --git a/include/media/stagefright/timedtext/TimedTextDriver.h b/include/media/stagefright/timedtext/TimedTextDriver.h index f23c337..37ef674 100644 --- a/include/media/stagefright/timedtext/TimedTextDriver.h +++ b/include/media/stagefright/timedtext/TimedTextDriver.h @@ -25,6 +25,7 @@ namespace android { class ALooper; +struct IMediaHTTPService; class MediaPlayerBase; class MediaSource; class Parcel; @@ -34,7 +35,9 @@ class DataSource; class TimedTextDriver { public: - TimedTextDriver(const wp<MediaPlayerBase> &listener); + TimedTextDriver( + const wp<MediaPlayerBase> &listener, + const sp<IMediaHTTPService> &httpService); ~TimedTextDriver(); @@ -77,6 +80,7 @@ private: sp<ALooper> mLooper; sp<TimedTextPlayer> mPlayer; wp<MediaPlayerBase> mListener; + sp<IMediaHTTPService> mHTTPService; // Variables to be guarded by mLock. State mState; diff --git a/include/private/media/AudioTrackShared.h b/include/private/media/AudioTrackShared.h index 2d033e6..3901e79 100644 --- a/include/private/media/AudioTrackShared.h +++ b/include/private/media/AudioTrackShared.h @@ -48,7 +48,7 @@ namespace android { #define CBLK_STREAM_END_DONE 0x400 // set by server on render completion, cleared by client //EL_FIXME 20 seconds may not be enough and must be reconciled with new obtainBuffer implementation -#define MAX_RUN_OFFLOADED_TIMEOUT_MS 20000 //assuming upto a maximum of 20 seconds of offloaded +#define MAX_RUN_OFFLOADED_TIMEOUT_MS 20000 // assuming up to a maximum of 20 seconds of offloaded struct AudioTrackSharedStreaming { // similar to NBAIO MonoPipe @@ -98,11 +98,7 @@ struct audio_track_cblk_t // The value should be used "for entertainment purposes only", // which means don't make important decisions based on it. - size_t frameCount_; // used during creation to pass actual track buffer size - // from AudioFlinger to client, and not referenced again - // FIXME remove here and replace by createTrack() in/out - // parameter - // renamed to "_" to detect incorrect use + uint32_t mPad1; // unused volatile int32_t mFutex; // event flag: down (P) by client, // up (V) by server or binderDied() or interrupt() |