Merge "liboboe: add _STREAM_ to OBOE_STATE, general cleanup of comments"
diff --git a/cmds/stagefright/codec.cpp b/cmds/stagefright/codec.cpp
index 26135d7..3108a67 100644
--- a/cmds/stagefright/codec.cpp
+++ b/cmds/stagefright/codec.cpp
@@ -32,7 +32,6 @@
#include <media/stagefright/foundation/ALooper.h>
#include <media/stagefright/foundation/AMessage.h>
#include <media/stagefright/foundation/AString.h>
-#include <media/stagefright/DataSource.h>
#include <media/stagefright/MediaCodec.h>
#include <media/stagefright/MediaCodecList.h>
#include <media/stagefright/MediaDefs.h>
@@ -401,8 +400,6 @@
ProcessState::self()->startThreadPool();
- DataSource::RegisterDefaultSniffers();
-
sp<ALooper> looper = new ALooper;
looper->start();
diff --git a/cmds/stagefright/mediafilter.cpp b/cmds/stagefright/mediafilter.cpp
index 410dd69..f219e69 100644
--- a/cmds/stagefright/mediafilter.cpp
+++ b/cmds/stagefright/mediafilter.cpp
@@ -30,7 +30,6 @@
#include <media/stagefright/foundation/ABuffer.h>
#include <media/stagefright/foundation/ADebug.h>
#include <media/stagefright/foundation/AMessage.h>
-#include <media/stagefright/DataSource.h>
#include <media/stagefright/MediaCodec.h>
#include <media/stagefright/NuMediaExtractor.h>
#include <media/stagefright/RenderScriptWrapper.h>
@@ -738,8 +737,6 @@
ProcessState::self()->startThreadPool();
- DataSource::RegisterDefaultSniffers();
-
android::sp<ALooper> looper = new ALooper;
looper->start();
diff --git a/cmds/stagefright/muxer.cpp b/cmds/stagefright/muxer.cpp
index 0a3bdf3..4a83a4a 100644
--- a/cmds/stagefright/muxer.cpp
+++ b/cmds/stagefright/muxer.cpp
@@ -29,7 +29,6 @@
#include <media/stagefright/foundation/ALooper.h>
#include <media/stagefright/foundation/AMessage.h>
#include <media/stagefright/foundation/AString.h>
-#include <media/stagefright/DataSource.h>
#include <media/stagefright/MediaCodec.h>
#include <media/stagefright/MediaDefs.h>
#include <media/stagefright/MediaMuxer.h>
@@ -319,9 +318,6 @@
}
ProcessState::self()->startThreadPool();
- // Make sure setDataSource() works.
- DataSource::RegisterDefaultSniffers();
-
sp<ALooper> looper = new ALooper;
looper->start();
diff --git a/cmds/stagefright/record.cpp b/cmds/stagefright/record.cpp
index 9aa0156..94c2e96 100644
--- a/cmds/stagefright/record.cpp
+++ b/cmds/stagefright/record.cpp
@@ -170,8 +170,6 @@
int main(int argc, char **argv) {
android::ProcessState::self()->startThreadPool();
- DataSource::RegisterDefaultSniffers();
-
#if 1
if (argc != 3) {
fprintf(stderr, "usage: %s <filename> <input_color_format>\n", argv[0]);
diff --git a/cmds/stagefright/sf2.cpp b/cmds/stagefright/sf2.cpp
index 76dbb78..12bbfd1 100644
--- a/cmds/stagefright/sf2.cpp
+++ b/cmds/stagefright/sf2.cpp
@@ -59,6 +59,114 @@
oldhandler(signum);
}
+namespace {
+
+enum {
+ kWhatFillThisBuffer = 'fill',
+ kWhatDrainThisBuffer = 'drai',
+ kWhatEOS = 'eos ',
+ kWhatStopCompleted = 'scom',
+ kWhatReleaseCompleted = 'rcom',
+ kWhatFlushCompleted = 'fcom',
+ kWhatError = 'erro',
+};
+
+class Sf2Callback : public CodecBase::Callback {
+public:
+ explicit Sf2Callback(const sp<AMessage> ¬ify);
+ ~Sf2Callback();
+
+ virtual void fillThisBuffer(IOMX::buffer_id bufferId, const sp<MediaCodecBuffer> &buffer,
+ const sp<AMessage> &reply) override;
+ virtual void drainThisBuffer(IOMX::buffer_id bufferId, const sp<MediaCodecBuffer> &buffer,
+ int32_t flags, const sp<AMessage> &reply) override;
+ virtual void onEos(status_t err) override;
+ virtual void onStopCompleted() override;
+ virtual void onReleaseCompleted() override;
+ virtual void onFlushCompleted() override;
+ virtual void onError(status_t err, enum ActionCode actionCode) override;
+ // Events below are not handled; thus ignore.
+ virtual void onComponentAllocated(const char *) override {}
+ virtual void onComponentConfigured(const sp<AMessage> &, const sp<AMessage> &) override {}
+ virtual void onInputSurfaceCreated(
+ const sp<AMessage> &,
+ const sp<AMessage> &,
+ const sp<BufferProducerWrapper> &) override {}
+ virtual void onInputSurfaceCreationFailed(status_t) override {}
+ virtual void onInputSurfaceAccepted(const sp<AMessage> &, const sp<AMessage> &) override {}
+ virtual void onInputSurfaceDeclined(status_t) override {}
+ virtual void onSignaledInputEOS(status_t) override {}
+ virtual void onBuffersAllocated(int32_t, const sp<CodecBase::PortDescription> &) override {}
+ virtual void onOutputFramesRendered(const std::list<FrameRenderTracker::Info> &) override {}
+private:
+ const sp<AMessage> mNotify;
+};
+
+Sf2Callback::Sf2Callback(const sp<AMessage> ¬ify) : mNotify(notify) {}
+
+Sf2Callback::~Sf2Callback() {}
+
+void Sf2Callback::fillThisBuffer(
+ IOMX::buffer_id bufferId,
+ const sp<MediaCodecBuffer> &buffer,
+ const sp<AMessage> &reply) {
+ sp<AMessage> notify(mNotify->dup());
+ notify->setInt32("what", kWhatFillThisBuffer);
+ notify->setInt32("buffer-id", bufferId);
+ notify->setObject("buffer", buffer);
+ notify->setMessage("reply", reply);
+ notify->post();
+}
+
+void Sf2Callback::drainThisBuffer(
+ IOMX::buffer_id bufferId,
+ const sp<MediaCodecBuffer> &buffer,
+ int32_t flags,
+ const sp<AMessage> &reply) {
+ sp<AMessage> notify(mNotify->dup());
+ notify->setInt32("what", kWhatDrainThisBuffer);
+ notify->setInt32("buffer-id", bufferId);
+ notify->setObject("buffer", buffer);
+ notify->setInt32("flags", flags);
+ notify->setMessage("reply", reply);
+ notify->post();
+}
+
+void Sf2Callback::onEos(status_t err) {
+ sp<AMessage> notify(mNotify->dup());
+ notify->setInt32("what", kWhatEOS);
+ notify->setInt32("err", err);
+ notify->post();
+}
+
+void Sf2Callback::onStopCompleted() {
+ sp<AMessage> notify(mNotify->dup());
+ notify->setInt32("what", kWhatStopCompleted);
+ notify->post();
+}
+
+void Sf2Callback::onReleaseCompleted() {
+ sp<AMessage> notify(mNotify->dup());
+ notify->setInt32("what", kWhatReleaseCompleted);
+ notify->post();
+}
+
+void Sf2Callback::onFlushCompleted() {
+ sp<AMessage> notify(mNotify->dup());
+ notify->setInt32("what", kWhatFlushCompleted);
+ notify->post();
+}
+
+void Sf2Callback::onError(status_t err, enum ActionCode actionCode) {
+ sp<AMessage> notify(mNotify->dup());
+ notify->setInt32("what", kWhatError);
+ notify->setInt32("err", err);
+ notify->setInt32("actionCode", actionCode);
+ notify->post();
+}
+
+} // namespace
+
struct Controller : public AHandler {
Controller(const char *uri, bool decodeAudio,
const sp<Surface> &surface, bool renderToSurface)
@@ -148,8 +256,8 @@
mDecodeLooper->registerHandler(mCodec);
- mCodec->setNotificationMessage(
- new AMessage(kWhatCodecNotify, this));
+ mCodec->setCallback(
+ std::make_shared<Sf2Callback>(new AMessage(kWhatCodecNotify, this)));
sp<AMessage> format = makeFormat(mSource->getFormat());
@@ -210,28 +318,28 @@
int32_t what;
CHECK(msg->findInt32("what", &what));
- if (what == CodecBase::kWhatFillThisBuffer) {
+ if (what == kWhatFillThisBuffer) {
onFillThisBuffer(msg);
- } else if (what == CodecBase::kWhatDrainThisBuffer) {
+ } else if (what == kWhatDrainThisBuffer) {
if ((mNumOutputBuffersReceived++ % 16) == 0) {
printf(".");
fflush(stdout);
}
onDrainThisBuffer(msg);
- } else if (what == CodecBase::kWhatEOS
- || what == CodecBase::kWhatError) {
- printf((what == CodecBase::kWhatEOS) ? "$\n" : "E\n");
+ } else if (what == kWhatEOS
+ || what == kWhatError) {
+ printf((what == kWhatEOS) ? "$\n" : "E\n");
printStatistics();
(new AMessage(kWhatStop, this))->post();
- } else if (what == CodecBase::kWhatFlushCompleted) {
+ } else if (what == kWhatFlushCompleted) {
mSeekState = SEEK_FLUSH_COMPLETED;
mCodec->signalResume();
(new AMessage(kWhatSeek, this))->post(5000000ll);
- } else if (what == CodecBase::kWhatStopCompleted ||
- what == CodecBase::kWhatReleaseCompleted) {
+ } else if (what == kWhatStopCompleted ||
+ what == kWhatReleaseCompleted) {
mDecodeLooper->unregisterHandler(mCodec->id());
if (mDecodeLooper != looper()) {
@@ -620,8 +728,6 @@
return 1;
}
- DataSource::RegisterDefaultSniffers();
-
sp<ALooper> looper = new ALooper;
looper->setName("sf2");
diff --git a/cmds/stagefright/stagefright.cpp b/cmds/stagefright/stagefright.cpp
index 2bb35cb..5e3a859 100644
--- a/cmds/stagefright/stagefright.cpp
+++ b/cmds/stagefright/stagefright.cpp
@@ -965,8 +965,6 @@
}
}
- DataSource::RegisterDefaultSniffers();
-
status_t err = OK;
for (int k = 0; k < argc && err == OK; ++k) {
diff --git a/cmds/stagefright/stream.cpp b/cmds/stagefright/stream.cpp
index 16ff39d..0cba8b9 100644
--- a/cmds/stagefright/stream.cpp
+++ b/cmds/stagefright/stream.cpp
@@ -301,8 +301,6 @@
int main(int argc, char **argv) {
android::ProcessState::self()->startThreadPool();
- DataSource::RegisterDefaultSniffers();
-
if (argc != 2) {
fprintf(stderr, "Usage: %s filename\n", argv[0]);
return 1;
diff --git a/include/media/stagefright/CodecBase.h b/include/media/stagefright/CodecBase.h
index 39a9089..25b8bf8 100644
--- a/include/media/stagefright/CodecBase.h
+++ b/include/media/stagefright/CodecBase.h
@@ -18,12 +18,15 @@
#define CODEC_BASE_H_
+#include <memory>
+
#include <stdint.h>
#define STRINGIFY_ENUMS
#include <media/IOMX.h>
#include <media/MediaCodecInfo.h>
+#include <media/stagefright/MediaErrors.h>
#include <media/stagefright/foundation/AHandler.h>
#include <media/stagefright/foundation/ColorUtils.h>
#include <media/hardware/HardwareAPI.h>
@@ -34,33 +37,159 @@
namespace android {
+class BufferProducerWrapper;
class MediaCodecBuffer;
struct PersistentSurface;
+struct RenderedFrameInfo;
class Surface;
struct CodecBase : public AHandler, /* static */ ColorUtils {
- enum {
- kWhatFillThisBuffer = 'fill',
- kWhatDrainThisBuffer = 'drai',
- kWhatEOS = 'eos ',
- kWhatStopCompleted = 'scom',
- kWhatReleaseCompleted = 'rcom',
- kWhatFlushCompleted = 'fcom',
- kWhatError = 'erro',
- kWhatComponentAllocated = 'cAll',
- kWhatComponentConfigured = 'cCon',
- kWhatInputSurfaceCreated = 'isfc',
- kWhatInputSurfaceAccepted = 'isfa',
- kWhatSignaledInputEOS = 'seos',
- kWhatBuffersAllocated = 'allc',
- kWhatOutputFramesRendered = 'outR',
+ struct PortDescription;
+
+ /**
+ * This interface defines events firing from CodecBase back to MediaCodec.
+ * All methods must not block.
+ */
+ class Callback {
+ public:
+ virtual ~Callback() = default;
+
+ /**
+ * Request MediaCodec to fill the specified input buffer.
+ *
+ * @param bufferId ID of the buffer, assigned by underlying component.
+ * @param buffer a buffer to be filled.
+ * @param reply a message to post once MediaCodec has filled the
+ * buffer.
+ */
+ virtual void fillThisBuffer(
+ IOMX::buffer_id bufferId,
+ const sp<MediaCodecBuffer> &buffer,
+ const sp<AMessage> &reply) = 0;
+ /**
+ * Request MediaCodec to drain the specified output buffer.
+ *
+ * @param bufferId ID of the buffer, assigned by underlying component.
+ * @param buffer a buffer to be filled.
+ * @param flags flags associated with this buffer (e.g. EOS).
+ * @param reply a message to post once MediaCodec has filled the
+ * buffer.
+ */
+ virtual void drainThisBuffer(
+ IOMX::buffer_id bufferId,
+ const sp<MediaCodecBuffer> &buffer,
+ int32_t flags,
+ const sp<AMessage> &reply) = 0;
+ /**
+ * Notify MediaCodec for seeing an output EOS.
+ *
+ * @param err the underlying cause of the EOS. If the value is neither
+ * OK nor ERROR_END_OF_STREAM, the EOS is declared
+ * prematurely for that error.
+ */
+ virtual void onEos(status_t err) = 0;
+ /**
+ * Notify MediaCodec that stop operation is complete.
+ */
+ virtual void onStopCompleted() = 0;
+ /**
+ * Notify MediaCodec that release operation is complete.
+ */
+ virtual void onReleaseCompleted() = 0;
+ /**
+ * Notify MediaCodec that flush operation is complete.
+ */
+ virtual void onFlushCompleted() = 0;
+ /**
+ * Notify MediaCodec that an error is occurred.
+ *
+ * @param err an error code for the occurred error.
+ * @param actionCode an action code for severity of the error.
+ */
+ virtual void onError(status_t err, enum ActionCode actionCode) = 0;
+ /**
+ * Notify MediaCodec that the underlying component is allocated.
+ *
+ * @param componentName the unique name of the component specified in
+ * MediaCodecList.
+ */
+ virtual void onComponentAllocated(const char *componentName) = 0;
+ /**
+ * Notify MediaCodec that the underlying component is configured.
+ *
+ * @param inputFormat an input format at configure time.
+ * @param outputFormat an output format at configure time.
+ */
+ virtual void onComponentConfigured(
+ const sp<AMessage> &inputFormat, const sp<AMessage> &outputFormat) = 0;
+ /**
+ * Notify MediaCodec that the input surface is created.
+ *
+ * @param inputFormat an input format at surface creation. Formats
+ * could change from the previous state as a result
+ * of creating a surface.
+ * @param outputFormat an output format at surface creation.
+ * @param inputSurface the created surface.
+ */
+ virtual void onInputSurfaceCreated(
+ const sp<AMessage> &inputFormat,
+ const sp<AMessage> &outputFormat,
+ const sp<BufferProducerWrapper> &inputSurface) = 0;
+ /**
+ * Notify MediaCodec that the input surface creation is failed.
+ *
+ * @param err an error code of the cause.
+ */
+ virtual void onInputSurfaceCreationFailed(status_t err) = 0;
+ /**
+ * Notify MediaCodec that the component accepted the provided input
+ * surface.
+ *
+ * @param inputFormat an input format at surface assignment. Formats
+ * could change from the previous state as a result
+ * of assigning a surface.
+ * @param outputFormat an output format at surface assignment.
+ */
+ virtual void onInputSurfaceAccepted(
+ const sp<AMessage> &inputFormat,
+ const sp<AMessage> &outputFormat) = 0;
+ /**
+ * Notify MediaCodec that the component declined the provided input
+ * surface.
+ *
+ * @param err an error code of the cause.
+ */
+ virtual void onInputSurfaceDeclined(status_t err) = 0;
+ /**
+ * Noitfy MediaCodec that the requested input EOS is sent to the input
+ * surface.
+ *
+ * @param err an error code returned from the surface. If there is no
+ * input surface, the value is INVALID_OPERATION.
+ */
+ virtual void onSignaledInputEOS(status_t err) = 0;
+ /**
+ * Notify MediaCodec with the allocated buffers.
+ *
+ * @param portIndex zero for input port, one for output port.
+ * @param portDesc a PortDescription object containing allocated
+ * buffers.
+ */
+ virtual void onBuffersAllocated(int32_t portIndex, const sp<PortDescription> &portDesc) = 0;
+ /**
+ * Notify MediaCodec that output frames are rendered with information on
+ * those frames.
+ *
+ * @param done a list of rendered frames.
+ */
+ virtual void onOutputFramesRendered(const std::list<RenderedFrameInfo> &done) = 0;
};
enum {
kMaxCodecBufferSize = 8192 * 4096 * 4, // 8K RGBA
};
- virtual void setNotificationMessage(const sp<AMessage> &msg) = 0;
+ void setCallback(std::shared_ptr<Callback> &&callback);
virtual void initiateAllocateComponent(const sp<AMessage> &msg) = 0;
virtual void initiateConfigureComponent(const sp<AMessage> &msg) = 0;
@@ -107,6 +236,8 @@
CodecBase();
virtual ~CodecBase();
+ std::shared_ptr<Callback> mCallback;
+
private:
DISALLOW_EVIL_CONSTRUCTORS(CodecBase);
};
diff --git a/include/media/stagefright/DataSource.h b/include/media/stagefright/DataSource.h
index 0254545..3479f76 100644
--- a/include/media/stagefright/DataSource.h
+++ b/include/media/stagefright/DataSource.h
@@ -102,17 +102,6 @@
////////////////////////////////////////////////////////////////////////////
- bool sniff(String8 *mimeType, float *confidence, sp<AMessage> *meta);
-
- // The sniffer can optionally fill in "meta" with an AMessage containing
- // a dictionary of values that helps the corresponding extractor initialize
- // its state without duplicating effort already exerted by the sniffer.
- typedef bool (*SnifferFunc)(
- const sp<DataSource> &source, String8 *mimeType,
- float *confidence, sp<AMessage> *meta);
-
- static void RegisterDefaultSniffers();
-
// for DRM
virtual sp<DecryptHandle> DrmInitialization(const char *mime = NULL) {
return NULL;
@@ -131,12 +120,6 @@
virtual ~DataSource() {}
private:
- static Mutex gSnifferMutex;
- static List<SnifferFunc> gSniffers;
- static bool gSniffersRegistered;
-
- static void RegisterSniffer_l(SnifferFunc func);
-
DataSource(const DataSource &);
DataSource &operator=(const DataSource &);
};
diff --git a/include/media/stagefright/FrameRenderTracker.h b/include/media/stagefright/FrameRenderTracker.h
index 8396657..6c572b8 100644
--- a/include/media/stagefright/FrameRenderTracker.h
+++ b/include/media/stagefright/FrameRenderTracker.h
@@ -32,58 +32,61 @@
class Fence;
class GraphicBuffer;
+// Tracks the render information about a frame. Frames go through several states while
+// the render information is tracked:
+//
+// 1. queued frame: mMediaTime and mGraphicBuffer are set for the frame. mFence is the
+// queue fence (read fence). mIndex is negative, and mRenderTimeNs is invalid.
+// Key characteristics: mFence is not NULL and mIndex is negative.
+//
+// 2. dequeued frame: mFence is updated with the dequeue fence (write fence). mIndex is set.
+// Key characteristics: mFence is not NULL and mIndex is non-negative. mRenderTime is still
+// invalid.
+//
+// 3. rendered frame or frame: mFence is cleared, mRenderTimeNs is set.
+// Key characteristics: mFence is NULL.
+//
+struct RenderedFrameInfo {
+ // set by client during onFrameQueued or onFrameRendered
+ int64_t getMediaTimeUs() const { return mMediaTimeUs; }
+
+ // -1 if frame is not yet rendered
+ nsecs_t getRenderTimeNs() const { return mRenderTimeNs; }
+
+ // set by client during updateRenderInfoForDequeuedBuffer; -1 otherwise
+ ssize_t getIndex() const { return mIndex; }
+
+ // creates information for a queued frame
+ RenderedFrameInfo(int64_t mediaTimeUs, const sp<GraphicBuffer> &graphicBuffer,
+ const sp<Fence> &fence)
+ : mMediaTimeUs(mediaTimeUs),
+ mRenderTimeNs(-1),
+ mIndex(-1),
+ mGraphicBuffer(graphicBuffer),
+ mFence(fence) {
+ }
+
+ // creates information for a frame rendered on a tunneled surface
+ RenderedFrameInfo(int64_t mediaTimeUs, nsecs_t renderTimeNs)
+ : mMediaTimeUs(mediaTimeUs),
+ mRenderTimeNs(renderTimeNs),
+ mIndex(-1),
+ mGraphicBuffer(NULL),
+ mFence(NULL) {
+ }
+
+private:
+ int64_t mMediaTimeUs;
+ nsecs_t mRenderTimeNs;
+ ssize_t mIndex; // to be used by client
+ sp<GraphicBuffer> mGraphicBuffer;
+ sp<Fence> mFence;
+
+ friend class FrameRenderTracker;
+};
+
struct FrameRenderTracker {
- // Tracks the render information about a frame. Frames go through several states while
- // the render information is tracked:
- //
- // 1. queued frame: mMediaTime and mGraphicBuffer are set for the frame. mFence is the
- // queue fence (read fence). mIndex is negative, and mRenderTimeNs is invalid.
- // Key characteristics: mFence is not NULL and mIndex is negative.
- //
- // 2. dequeued frame: mFence is updated with the dequeue fence (write fence). mIndex is set.
- // Key characteristics: mFence is not NULL and mIndex is non-negative. mRenderTime is still
- // invalid.
- //
- // 3. rendered frame or frame: mFence is cleared, mRenderTimeNs is set.
- // Key characteristics: mFence is NULL.
- //
- struct Info {
- // set by client during onFrameQueued or onFrameRendered
- int64_t getMediaTimeUs() const { return mMediaTimeUs; }
-
- // -1 if frame is not yet rendered
- nsecs_t getRenderTimeNs() const { return mRenderTimeNs; }
-
- // set by client during updateRenderInfoForDequeuedBuffer; -1 otherwise
- ssize_t getIndex() const { return mIndex; }
-
- // creates information for a queued frame
- Info(int64_t mediaTimeUs, const sp<GraphicBuffer> &graphicBuffer, const sp<Fence> &fence)
- : mMediaTimeUs(mediaTimeUs),
- mRenderTimeNs(-1),
- mIndex(-1),
- mGraphicBuffer(graphicBuffer),
- mFence(fence) {
- }
-
- // creates information for a frame rendered on a tunneled surface
- Info(int64_t mediaTimeUs, nsecs_t renderTimeNs)
- : mMediaTimeUs(mediaTimeUs),
- mRenderTimeNs(renderTimeNs),
- mIndex(-1),
- mGraphicBuffer(NULL),
- mFence(NULL) {
- }
-
- private:
- int64_t mMediaTimeUs;
- nsecs_t mRenderTimeNs;
- ssize_t mIndex; // to be used by client
- sp<GraphicBuffer> mGraphicBuffer;
- sp<Fence> mFence;
-
- friend class FrameRenderTracker;
- };
+ typedef RenderedFrameInfo Info;
FrameRenderTracker();
diff --git a/include/media/stagefright/MediaExtractor.h b/include/media/stagefright/MediaExtractor.h
index 6bf8c9e..e5ee72e 100644
--- a/include/media/stagefright/MediaExtractor.h
+++ b/include/media/stagefright/MediaExtractor.h
@@ -80,6 +80,24 @@
private:
bool mIsDrm;
+ typedef bool (*SnifferFunc)(
+ const sp<DataSource> &source, String8 *mimeType,
+ float *confidence, sp<AMessage> *meta);
+
+ static Mutex gSnifferMutex;
+ static List<SnifferFunc> gSniffers;
+ static bool gSniffersRegistered;
+
+ // The sniffer can optionally fill in "meta" with an AMessage containing
+ // a dictionary of values that helps the corresponding extractor initialize
+ // its state without duplicating effort already exerted by the sniffer.
+ static void RegisterSniffer_l(SnifferFunc func);
+
+ static bool sniff(const sp<DataSource> &source,
+ String8 *mimeType, float *confidence, sp<AMessage> *meta);
+
+ static void RegisterDefaultSniffers();
+
MediaExtractor(const MediaExtractor &);
MediaExtractor &operator=(const MediaExtractor &);
};
diff --git a/include/media/stagefright/MediaFilter.h b/include/media/stagefright/MediaFilter.h
index 0e39431..a0e580b 100644
--- a/include/media/stagefright/MediaFilter.h
+++ b/include/media/stagefright/MediaFilter.h
@@ -28,8 +28,6 @@
struct MediaFilter : public CodecBase {
MediaFilter();
- virtual void setNotificationMessage(const sp<AMessage> &msg);
-
virtual void initiateAllocateComponent(const sp<AMessage> &msg);
virtual void initiateConfigureComponent(const sp<AMessage> &msg);
virtual void initiateCreateInputSurface();
@@ -120,7 +118,6 @@
int32_t mColorFormatIn, mColorFormatOut;
size_t mMaxInputSize, mMaxOutputSize;
int32_t mGeneration;
- sp<AMessage> mNotify;
sp<AMessage> mInputFormat;
sp<AMessage> mOutputFormat;
diff --git a/media/libmediaplayerservice/nuplayer/GenericSource.cpp b/media/libmediaplayerservice/nuplayer/GenericSource.cpp
index cf1f84b..4956fa0 100644
--- a/media/libmediaplayerservice/nuplayer/GenericSource.cpp
+++ b/media/libmediaplayerservice/nuplayer/GenericSource.cpp
@@ -68,7 +68,6 @@
mPendingReadBufferTypes(0) {
mBufferingMonitor = new BufferingMonitor(notify);
resetDataSource();
- DataSource::RegisterDefaultSniffers();
}
void NuPlayer::GenericSource::resetDataSource() {
diff --git a/media/libstagefright/ACodec.cpp b/media/libstagefright/ACodec.cpp
index 4a02289..a0c8ace 100644
--- a/media/libstagefright/ACodec.cpp
+++ b/media/libstagefright/ACodec.cpp
@@ -934,20 +934,12 @@
return err;
}
- sp<AMessage> notify = mNotify->dup();
- notify->setInt32("what", CodecBase::kWhatBuffersAllocated);
-
- notify->setInt32("portIndex", portIndex);
-
sp<PortDescription> desc = new PortDescription;
-
for (size_t i = 0; i < mBuffers[portIndex].size(); ++i) {
const BufferInfo &info = mBuffers[portIndex][i];
desc->addBuffer(info.mBufferID, info.mData);
}
-
- notify->setObject("portDesc", desc);
- notify->post();
+ mCallback->onBuffersAllocated(portIndex, desc);
return OK;
}
@@ -1309,8 +1301,6 @@
}
void ACodec::notifyOfRenderedFrames(bool dropIncomplete, FrameRenderTracker::Info *until) {
- sp<AMessage> msg = mNotify->dup();
- msg->setInt32("what", CodecBase::kWhatOutputFramesRendered);
std::list<FrameRenderTracker::Info> done =
mRenderTracker.checkFencesAndGetRenderedFrames(until, dropIncomplete);
@@ -1326,9 +1316,7 @@
}
}
- if (MediaCodec::CreateFramesRenderedMessage(done, msg)) {
- msg->post();
- }
+ mCallback->onOutputFramesRendered(done);
}
ACodec::BufferInfo *ACodec::dequeueBufferFromNativeWindow() {
@@ -5118,8 +5106,6 @@
}
void ACodec::signalError(OMX_ERRORTYPE error, status_t internalError) {
- sp<AMessage> notify = mNotify->dup();
- notify->setInt32("what", CodecBase::kWhatError);
ALOGE("signalError(omxError %#x, internalError %d)", error, internalError);
if (internalError == UNKNOWN_ERROR) { // find better error code
@@ -5132,10 +5118,7 @@
}
mFatalError = true;
-
- notify->setInt32("err", internalError);
- notify->setInt32("actionCode", ACTION_CODE_FATAL); // could translate from OMX error.
- notify->post();
+ mCallback->onError(internalError, ACTION_CODE_FATAL);
}
status_t ACodec::requestIDRFrame() {
@@ -5262,9 +5245,7 @@
status_t err = mCodec->mOMXNode->freeNode();
ALOGE_IF("[%s] failed to release codec instance: err=%d",
mCodec->mComponentName.c_str(), err);
- sp<AMessage> notify = mCodec->mNotify->dup();
- notify->setInt32("what", CodecBase::kWhatReleaseCompleted);
- notify->post();
+ mCodec->mCallback->onReleaseCompleted();
break;
}
@@ -5488,21 +5469,11 @@
CHECK_EQ((int)info->mStatus, (int)BufferInfo::OWNED_BY_US);
- sp<AMessage> notify = mCodec->mNotify->dup();
- notify->setInt32("what", CodecBase::kWhatFillThisBuffer);
- notify->setInt32("buffer-id", info->mBufferID);
-
info->mData->setFormat(mCodec->mInputFormat);
- notify->setObject("buffer", info->mData);
- info->mData.clear();
-
sp<AMessage> reply = new AMessage(kWhatInputBufferFilled, mCodec);
reply->setInt32("buffer-id", info->mBufferID);
-
- notify->setMessage("reply", reply);
-
- notify->post();
-
+ mCodec->mCallback->fillThisBuffer(info->mBufferID, info->mData, reply);
+ info->mData.clear();
info->mStatus = BufferInfo::OWNED_BY_UPSTREAM;
}
@@ -5852,8 +5823,7 @@
break;
}
- sp<AMessage> reply =
- new AMessage(kWhatOutputBufferDrained, mCodec);
+ sp<AMessage> reply = new AMessage(kWhatOutputBufferDrained, mCodec);
sp<MediaCodecBuffer> buffer = info->mData;
if (mCodec->mOutputFormat != mCodec->mLastOutputFormat && rangeLength > 0) {
@@ -5909,29 +5879,18 @@
}
buffer->meta()->setInt64("timeUs", timeUs);
- sp<AMessage> notify = mCodec->mNotify->dup();
- notify->setInt32("what", CodecBase::kWhatDrainThisBuffer);
- notify->setInt32("buffer-id", info->mBufferID);
- notify->setObject("buffer", buffer);
info->mData.clear();
- notify->setInt32("flags", flags);
reply->setInt32("buffer-id", info->mBufferID);
- notify->setMessage("reply", reply);
-
- notify->post();
+ mCodec->mCallback->drainThisBuffer(info->mBufferID, buffer, flags, reply);
info->mStatus = BufferInfo::OWNED_BY_DOWNSTREAM;
if (flags & OMX_BUFFERFLAG_EOS) {
ALOGV("[%s] saw output EOS", mCodec->mComponentName.c_str());
- sp<AMessage> notify = mCodec->mNotify->dup();
- notify->setInt32("what", CodecBase::kWhatEOS);
- notify->setInt32("err", mCodec->mInputEOSResult);
- notify->post();
-
+ mCodec->mCallback->onEos(mCodec->mInputEOSResult);
mCodec->mPortEOS[kPortIndexOutput] = true;
}
break;
@@ -6150,22 +6109,18 @@
"keepComponentAllocated", &keepComponentAllocated));
ALOGW_IF(keepComponentAllocated,
"cannot keep component allocated on shutdown in Uninitialized state");
-
- sp<AMessage> notify = mCodec->mNotify->dup();
- notify->setInt32("what", keepComponentAllocated ?
- CodecBase::kWhatStopCompleted : CodecBase::kWhatReleaseCompleted);
- notify->post();
-
+ if (keepComponentAllocated) {
+ mCodec->mCallback->onStopCompleted();
+ } else {
+ mCodec->mCallback->onReleaseCompleted();
+ }
handled = true;
break;
}
case ACodec::kWhatFlush:
{
- sp<AMessage> notify = mCodec->mNotify->dup();
- notify->setInt32("what", CodecBase::kWhatFlushCompleted);
- notify->post();
-
+ mCodec->mCallback->onFlushCompleted();
handled = true;
break;
}
@@ -6293,14 +6248,7 @@
omxNode->setQuirks(quirks);
mCodec->mOMX = omx;
mCodec->mOMXNode = omxNode;
-
- {
- sp<AMessage> notify = mCodec->mNotify->dup();
- notify->setInt32("what", CodecBase::kWhatComponentAllocated);
- notify->setString("componentName", mCodec->mComponentName.c_str());
- notify->post();
- }
-
+ mCodec->mCallback->onComponentAllocated(mCodec->mComponentName.c_str());
mCodec->changeState(mCodec->mLoadedState);
return true;
@@ -6349,10 +6297,11 @@
}
if (mCodec->mExplicitShutdown) {
- sp<AMessage> notify = mCodec->mNotify->dup();
- notify->setInt32("what", keepComponentAllocated ?
- CodecBase::kWhatStopCompleted : CodecBase::kWhatReleaseCompleted);
- notify->post();
+ if (keepComponentAllocated) {
+ mCodec->mCallback->onStopCompleted();
+ } else {
+ mCodec->mCallback->onReleaseCompleted();
+ }
mCodec->mExplicitShutdown = false;
}
}
@@ -6404,10 +6353,7 @@
case ACodec::kWhatFlush:
{
- sp<AMessage> notify = mCodec->mNotify->dup();
- notify->setInt32("what", CodecBase::kWhatFlushCompleted);
- notify->post();
-
+ mCodec->mCallback->onFlushCompleted();
handled = true;
break;
}
@@ -6440,13 +6386,7 @@
return false;
}
- {
- sp<AMessage> notify = mCodec->mNotify->dup();
- notify->setInt32("what", CodecBase::kWhatComponentConfigured);
- notify->setMessage("input-format", mCodec->mInputFormat);
- notify->setMessage("output-format", mCodec->mOutputFormat);
- notify->post();
- }
+ mCodec->mCallback->onComponentConfigured(mCodec->mInputFormat, mCodec->mOutputFormat);
return true;
}
@@ -6568,9 +6508,6 @@
const sp<AMessage> & /* msg */) {
ALOGV("onCreateInputSurface");
- sp<AMessage> notify = mCodec->mNotify->dup();
- notify->setInt32("what", CodecBase::kWhatInputSurfaceCreated);
-
sp<IGraphicBufferProducer> bufferProducer;
status_t err = mCodec->mOMX->createInputSurface(
&bufferProducer, &mCodec->mGraphicBufferSource);
@@ -6580,10 +6517,9 @@
}
if (err == OK) {
- notify->setMessage("input-format", mCodec->mInputFormat);
- notify->setMessage("output-format", mCodec->mOutputFormat);
-
- notify->setObject("input-surface",
+ mCodec->mCallback->onInputSurfaceCreated(
+ mCodec->mInputFormat,
+ mCodec->mOutputFormat,
new BufferProducerWrapper(bufferProducer));
} else {
// Can't use mCodec->signalError() here -- MediaCodec won't forward
@@ -6591,18 +6527,13 @@
// send a kWhatInputSurfaceCreated with an error value instead.
ALOGE("[%s] onCreateInputSurface returning error %d",
mCodec->mComponentName.c_str(), err);
- notify->setInt32("err", err);
+ mCodec->mCallback->onInputSurfaceCreationFailed(err);
}
- notify->post();
}
-void ACodec::LoadedState::onSetInputSurface(
- const sp<AMessage> &msg) {
+void ACodec::LoadedState::onSetInputSurface(const sp<AMessage> &msg) {
ALOGV("onSetInputSurface");
- sp<AMessage> notify = mCodec->mNotify->dup();
- notify->setInt32("what", CodecBase::kWhatInputSurfaceAccepted);
-
sp<RefBase> obj;
CHECK(msg->findObject("input-surface", &obj));
sp<PersistentSurface> surface = static_cast<PersistentSurface *>(obj.get());
@@ -6611,17 +6542,16 @@
status_t err = setupInputSurface();
if (err == OK) {
- notify->setMessage("input-format", mCodec->mInputFormat);
- notify->setMessage("output-format", mCodec->mOutputFormat);
+ mCodec->mCallback->onInputSurfaceAccepted(
+ mCodec->mInputFormat, mCodec->mOutputFormat);
} else {
// Can't use mCodec->signalError() here -- MediaCodec won't forward
// the error through because it's in the "configured" state. We
// send a kWhatInputSurfaceAccepted with an error value instead.
ALOGE("[%s] onSetInputSurface returning error %d",
mCodec->mComponentName.c_str(), err);
- notify->setInt32("err", err);
+ mCodec->mCallback->onInputSurfaceDeclined(err);
}
- notify->post();
}
void ACodec::LoadedState::onStart() {
@@ -6699,9 +6629,7 @@
case kWhatFlush:
{
// We haven't even started yet, so we're flushed alright...
- sp<AMessage> notify = mCodec->mNotify->dup();
- notify->setInt32("what", CodecBase::kWhatFlushCompleted);
- notify->post();
+ mCodec->mCallback->onFlushCompleted();
return true;
}
@@ -6771,10 +6699,7 @@
case kWhatFlush:
{
// We haven't even started yet, so we're flushed alright...
- sp<AMessage> notify = mCodec->mNotify->dup();
- notify->setInt32("what", CodecBase::kWhatFlushCompleted);
- notify->post();
-
+ mCodec->mCallback->onFlushCompleted();
return true;
}
@@ -7149,17 +7074,11 @@
}
void ACodec::onSignalEndOfInputStream() {
- sp<AMessage> notify = mNotify->dup();
- notify->setInt32("what", CodecBase::kWhatSignaledInputEOS);
-
status_t err = INVALID_OPERATION;
if (mGraphicBufferSource != NULL) {
err = statusFromBinderStatus(mGraphicBufferSource->signalEndOfInputStream());
}
- if (err != OK) {
- notify->setInt32("err", err);
- }
- notify->post();
+ mCallback->onSignaledInputEOS(err);
}
bool ACodec::ExecutingState::onOMXFrameRendered(int64_t mediaTimeUs, nsecs_t systemNano) {
@@ -7636,9 +7555,7 @@
mCodec->mRenderTracker.clear(systemTime(CLOCK_MONOTONIC));
- sp<AMessage> notify = mCodec->mNotify->dup();
- notify->setInt32("what", CodecBase::kWhatFlushCompleted);
- notify->post();
+ mCodec->mCallback->onFlushCompleted();
mCodec->mPortEOS[kPortIndexInput] =
mCodec->mPortEOS[kPortIndexOutput] = false;
diff --git a/media/libstagefright/CodecBase.cpp b/media/libstagefright/CodecBase.cpp
index f729d4d..3eca52a 100644
--- a/media/libstagefright/CodecBase.cpp
+++ b/media/libstagefright/CodecBase.cpp
@@ -35,4 +35,8 @@
CodecBase::PortDescription::~PortDescription() {
}
+void CodecBase::setCallback(std::shared_ptr<Callback> &&callback) {
+ mCallback = callback;
+}
+
} // namespace android
diff --git a/media/libstagefright/DataSource.cpp b/media/libstagefright/DataSource.cpp
index c78f1e9..a9536b9 100644
--- a/media/libstagefright/DataSource.cpp
+++ b/media/libstagefright/DataSource.cpp
@@ -111,79 +111,6 @@
////////////////////////////////////////////////////////////////////////////////
-Mutex DataSource::gSnifferMutex;
-List<DataSource::SnifferFunc> DataSource::gSniffers;
-bool DataSource::gSniffersRegistered = false;
-
-bool DataSource::sniff(
- String8 *mimeType, float *confidence, sp<AMessage> *meta) {
- *mimeType = "";
- *confidence = 0.0f;
- meta->clear();
-
- {
- Mutex::Autolock autoLock(gSnifferMutex);
- if (!gSniffersRegistered) {
- return false;
- }
- }
-
- for (List<SnifferFunc>::iterator it = gSniffers.begin();
- it != gSniffers.end(); ++it) {
- String8 newMimeType;
- float newConfidence;
- sp<AMessage> newMeta;
- if ((*it)(this, &newMimeType, &newConfidence, &newMeta)) {
- if (newConfidence > *confidence) {
- *mimeType = newMimeType;
- *confidence = newConfidence;
- *meta = newMeta;
- }
- }
- }
-
- return *confidence > 0.0;
-}
-
-// static
-void DataSource::RegisterSniffer_l(SnifferFunc func) {
- for (List<SnifferFunc>::iterator it = gSniffers.begin();
- it != gSniffers.end(); ++it) {
- if (*it == func) {
- return;
- }
- }
-
- gSniffers.push_back(func);
-}
-
-// static
-void DataSource::RegisterDefaultSniffers() {
- Mutex::Autolock autoLock(gSnifferMutex);
- if (gSniffersRegistered) {
- return;
- }
-
- RegisterSniffer_l(SniffMPEG4);
- RegisterSniffer_l(SniffMatroska);
- RegisterSniffer_l(SniffOgg);
- RegisterSniffer_l(SniffWAV);
- RegisterSniffer_l(SniffFLAC);
- RegisterSniffer_l(SniffAMR);
- RegisterSniffer_l(SniffMPEG2TS);
- RegisterSniffer_l(SniffMP3);
- RegisterSniffer_l(SniffAAC);
- RegisterSniffer_l(SniffMPEG2PS);
- RegisterSniffer_l(SniffMidi);
-
- char value[PROPERTY_VALUE_MAX];
- if (property_get("drm.service.enabled", value, NULL)
- && (!strcmp(value, "1") || !strcasecmp(value, "true"))) {
- RegisterSniffer_l(SniffDRM);
- }
- gSniffersRegistered = true;
-}
-
// static
sp<DataSource> DataSource::CreateFromURI(
const sp<IMediaHTTPService> &httpService,
diff --git a/media/libstagefright/MediaCodec.cpp b/media/libstagefright/MediaCodec.cpp
index 7c725ae..f29f786 100644
--- a/media/libstagefright/MediaCodec.cpp
+++ b/media/libstagefright/MediaCodec.cpp
@@ -67,6 +67,8 @@
static const int kMaxRetry = 2;
static const int kMaxReclaimWaitTimeInUs = 500000; // 0.5s
+////////////////////////////////////////////////////////////////////////////////
+
struct ResourceManagerClient : public BnResourceManagerClient {
explicit ResourceManagerClient(MediaCodec* codec) : mMediaCodec(codec) {}
@@ -171,6 +173,206 @@
return mService->reclaimResource(mPid, resources);
}
+////////////////////////////////////////////////////////////////////////////////
+
+namespace {
+
+enum {
+ kWhatFillThisBuffer = 'fill',
+ kWhatDrainThisBuffer = 'drai',
+ kWhatEOS = 'eos ',
+ kWhatStopCompleted = 'scom',
+ kWhatReleaseCompleted = 'rcom',
+ kWhatFlushCompleted = 'fcom',
+ kWhatError = 'erro',
+ kWhatComponentAllocated = 'cAll',
+ kWhatComponentConfigured = 'cCon',
+ kWhatInputSurfaceCreated = 'isfc',
+ kWhatInputSurfaceAccepted = 'isfa',
+ kWhatSignaledInputEOS = 'seos',
+ kWhatBuffersAllocated = 'allc',
+ kWhatOutputFramesRendered = 'outR',
+};
+
+class MediaCodecCallback : public CodecBase::Callback {
+public:
+ explicit MediaCodecCallback(const sp<AMessage> ¬ify);
+ virtual ~MediaCodecCallback();
+
+ virtual void fillThisBuffer(IOMX::buffer_id bufferId, const sp<MediaCodecBuffer> &buffer,
+ const sp<AMessage> &reply) override;
+ virtual void drainThisBuffer(IOMX::buffer_id bufferId, const sp<MediaCodecBuffer> &buffer,
+ int32_t flags, const sp<AMessage> &reply) override;
+ virtual void onEos(status_t err) override;
+ virtual void onStopCompleted() override;
+ virtual void onReleaseCompleted() override;
+ virtual void onFlushCompleted() override;
+ virtual void onError(status_t err, enum ActionCode actionCode) override;
+ virtual void onComponentAllocated(const char *componentName) override;
+ virtual void onComponentConfigured(
+ const sp<AMessage> &inputFormat, const sp<AMessage> &outputFormat) override;
+ virtual void onInputSurfaceCreated(
+ const sp<AMessage> &inputFormat,
+ const sp<AMessage> &outputFormat,
+ const sp<BufferProducerWrapper> &inputSurface) override;
+ virtual void onInputSurfaceCreationFailed(status_t err) override;
+ virtual void onInputSurfaceAccepted(
+ const sp<AMessage> &inputFormat,
+ const sp<AMessage> &outputFormat) override;
+ virtual void onInputSurfaceDeclined(status_t err) override;
+ virtual void onSignaledInputEOS(status_t err) override;
+ virtual void onBuffersAllocated(
+ int32_t portIndex, const sp<CodecBase::PortDescription> &portDesc) override;
+ virtual void onOutputFramesRendered(const std::list<FrameRenderTracker::Info> &done) override;
+private:
+ const sp<AMessage> mNotify;
+};
+
+MediaCodecCallback::MediaCodecCallback(const sp<AMessage> ¬ify) : mNotify(notify) {}
+
+MediaCodecCallback::~MediaCodecCallback() {}
+
+void MediaCodecCallback::fillThisBuffer(
+ IOMX::buffer_id bufferId,
+ const sp<MediaCodecBuffer> &buffer,
+ const sp<AMessage> &reply) {
+ sp<AMessage> notify(mNotify->dup());
+ notify->setInt32("what", kWhatFillThisBuffer);
+ notify->setInt32("buffer-id", bufferId);
+ notify->setObject("buffer", buffer);
+ notify->setMessage("reply", reply);
+ notify->post();
+}
+
+void MediaCodecCallback::drainThisBuffer(
+ IOMX::buffer_id bufferId,
+ const sp<MediaCodecBuffer> &buffer,
+ int32_t flags,
+ const sp<AMessage> &reply) {
+ sp<AMessage> notify(mNotify->dup());
+ notify->setInt32("what", kWhatDrainThisBuffer);
+ notify->setInt32("buffer-id", bufferId);
+ notify->setObject("buffer", buffer);
+ notify->setInt32("flags", flags);
+ notify->setMessage("reply", reply);
+ notify->post();
+}
+
+void MediaCodecCallback::onEos(status_t err) {
+ sp<AMessage> notify(mNotify->dup());
+ notify->setInt32("what", kWhatEOS);
+ notify->setInt32("err", err);
+ notify->post();
+}
+
+void MediaCodecCallback::onStopCompleted() {
+ sp<AMessage> notify(mNotify->dup());
+ notify->setInt32("what", kWhatStopCompleted);
+ notify->post();
+}
+
+void MediaCodecCallback::onReleaseCompleted() {
+ sp<AMessage> notify(mNotify->dup());
+ notify->setInt32("what", kWhatReleaseCompleted);
+ notify->post();
+}
+
+void MediaCodecCallback::onFlushCompleted() {
+ sp<AMessage> notify(mNotify->dup());
+ notify->setInt32("what", kWhatFlushCompleted);
+ notify->post();
+}
+
+void MediaCodecCallback::onError(status_t err, enum ActionCode actionCode) {
+ sp<AMessage> notify(mNotify->dup());
+ notify->setInt32("what", kWhatError);
+ notify->setInt32("err", err);
+ notify->setInt32("actionCode", actionCode);
+ notify->post();
+}
+
+void MediaCodecCallback::onComponentAllocated(const char *componentName) {
+ sp<AMessage> notify(mNotify->dup());
+ notify->setInt32("what", kWhatComponentAllocated);
+ notify->setString("componentName", componentName);
+ notify->post();
+}
+
+void MediaCodecCallback::onComponentConfigured(
+ const sp<AMessage> &inputFormat, const sp<AMessage> &outputFormat) {
+ sp<AMessage> notify(mNotify->dup());
+ notify->setInt32("what", kWhatComponentConfigured);
+ notify->setMessage("input-format", inputFormat);
+ notify->setMessage("output-format", outputFormat);
+ notify->post();
+}
+
+void MediaCodecCallback::onInputSurfaceCreated(
+ const sp<AMessage> &inputFormat,
+ const sp<AMessage> &outputFormat,
+ const sp<BufferProducerWrapper> &inputSurface) {
+ sp<AMessage> notify(mNotify->dup());
+ notify->setInt32("what", kWhatInputSurfaceCreated);
+ notify->setMessage("input-format", inputFormat);
+ notify->setMessage("output-format", outputFormat);
+ notify->setObject("input-surface", inputSurface);
+ notify->post();
+}
+
+void MediaCodecCallback::onInputSurfaceCreationFailed(status_t err) {
+ sp<AMessage> notify(mNotify->dup());
+ notify->setInt32("what", kWhatInputSurfaceCreated);
+ notify->setInt32("err", err);
+ notify->post();
+}
+
+void MediaCodecCallback::onInputSurfaceAccepted(
+ const sp<AMessage> &inputFormat,
+ const sp<AMessage> &outputFormat) {
+ sp<AMessage> notify(mNotify->dup());
+ notify->setInt32("what", kWhatInputSurfaceAccepted);
+ notify->setMessage("input-format", inputFormat);
+ notify->setMessage("output-format", outputFormat);
+ notify->post();
+}
+
+void MediaCodecCallback::onInputSurfaceDeclined(status_t err) {
+ sp<AMessage> notify(mNotify->dup());
+ notify->setInt32("what", kWhatInputSurfaceAccepted);
+ notify->setInt32("err", err);
+ notify->post();
+}
+
+void MediaCodecCallback::onSignaledInputEOS(status_t err) {
+ sp<AMessage> notify(mNotify->dup());
+ notify->setInt32("what", kWhatSignaledInputEOS);
+ if (err != OK) {
+ notify->setInt32("err", err);
+ }
+ notify->post();
+}
+
+void MediaCodecCallback::onBuffersAllocated(
+ int32_t portIndex, const sp<CodecBase::PortDescription> &portDesc) {
+ sp<AMessage> notify(mNotify->dup());
+ notify->setInt32("what", kWhatBuffersAllocated);
+ notify->setInt32("portIndex", portIndex);
+ notify->setObject("portDesc", portDesc);
+ notify->post();
+}
+
+void MediaCodecCallback::onOutputFramesRendered(const std::list<FrameRenderTracker::Info> &done) {
+ sp<AMessage> notify(mNotify->dup());
+ notify->setInt32("what", kWhatOutputFramesRendered);
+ if (MediaCodec::CreateFramesRenderedMessage(done, notify)) {
+ notify->post();
+ }
+}
+
+} // namespace
+
+////////////////////////////////////////////////////////////////////////////////
+
// static
sp<MediaCodec> MediaCodec::CreateByType(
const sp<ALooper> &looper, const AString &mime, bool encoder, status_t *err, pid_t pid,
@@ -370,7 +572,8 @@
mLooper->registerHandler(this);
- mCodec->setNotificationMessage(new AMessage(kWhatCodecNotify, this));
+ mCodec->setCallback(
+ std::make_shared<MediaCodecCallback>(new AMessage(kWhatCodecNotify, this)));
sp<AMessage> msg = new AMessage(kWhatInit, this);
msg->setString("name", name);
@@ -1056,7 +1259,7 @@
CHECK(msg->findInt32("what", &what));
switch (what) {
- case CodecBase::kWhatError:
+ case kWhatError:
{
int32_t err, actionCode;
CHECK(msg->findInt32("err", &err));
@@ -1191,7 +1394,7 @@
break;
}
- case CodecBase::kWhatComponentAllocated:
+ case kWhatComponentAllocated:
{
CHECK_EQ(mState, INITIALIZING);
setState(INITIALIZED);
@@ -1223,7 +1426,7 @@
break;
}
- case CodecBase::kWhatComponentConfigured:
+ case kWhatComponentConfigured:
{
if (mState == UNINITIALIZED || mState == INITIALIZED) {
// In case a kWhatError message came in and replied with error,
@@ -1252,7 +1455,7 @@
break;
}
- case CodecBase::kWhatInputSurfaceCreated:
+ case kWhatInputSurfaceCreated:
{
// response to initiateCreateInputSurface()
status_t err = NO_ERROR;
@@ -1276,7 +1479,7 @@
break;
}
- case CodecBase::kWhatInputSurfaceAccepted:
+ case kWhatInputSurfaceAccepted:
{
// response to initiateSetInputSurface()
status_t err = NO_ERROR;
@@ -1292,7 +1495,7 @@
break;
}
- case CodecBase::kWhatSignaledInputEOS:
+ case kWhatSignaledInputEOS:
{
// response to signalEndOfInputStream()
sp<AMessage> response = new AMessage;
@@ -1305,7 +1508,7 @@
}
- case CodecBase::kWhatBuffersAllocated:
+ case kWhatBuffersAllocated:
{
Mutex::Autolock al(mBufferLock);
int32_t portIndex;
@@ -1376,7 +1579,7 @@
break;
}
- case CodecBase::kWhatOutputFramesRendered:
+ case kWhatOutputFramesRendered:
{
// ignore these in all states except running, and check that we have a
// notification set
@@ -1388,7 +1591,7 @@
break;
}
- case CodecBase::kWhatFillThisBuffer:
+ case kWhatFillThisBuffer:
{
/* size_t index = */updateBuffers(kPortIndexInput, msg);
@@ -1446,7 +1649,7 @@
break;
}
- case CodecBase::kWhatDrainThisBuffer:
+ case kWhatDrainThisBuffer:
{
/* size_t index = */updateBuffers(kPortIndexOutput, msg);
@@ -1543,14 +1746,14 @@
break;
}
- case CodecBase::kWhatEOS:
+ case kWhatEOS:
{
// We already notify the client of this by using the
// corresponding flag in "onOutputBufferReady".
break;
}
- case CodecBase::kWhatStopCompleted:
+ case kWhatStopCompleted:
{
if (mState != STOPPING) {
ALOGW("Received kWhatStopCompleted in state %d", mState);
@@ -1561,7 +1764,7 @@
break;
}
- case CodecBase::kWhatReleaseCompleted:
+ case kWhatReleaseCompleted:
{
if (mState != RELEASING) {
ALOGW("Received kWhatReleaseCompleted in state %d", mState);
@@ -1578,7 +1781,7 @@
break;
}
- case CodecBase::kWhatFlushCompleted:
+ case kWhatFlushCompleted:
{
if (mState != FLUSHING) {
ALOGW("received FlushCompleted message in state %d",
diff --git a/media/libstagefright/MediaExtractor.cpp b/media/libstagefright/MediaExtractor.cpp
index 66bf7cb..9362a07 100644
--- a/media/libstagefright/MediaExtractor.cpp
+++ b/media/libstagefright/MediaExtractor.cpp
@@ -185,14 +185,14 @@
const sp<DataSource> &source, const char *mime) {
ALOGV("MediaExtractor::CreateFromService %s", mime);
- DataSource::RegisterDefaultSniffers();
+ RegisterDefaultSniffers();
sp<AMessage> meta;
String8 tmp;
if (mime == NULL) {
float confidence;
- if (!source->sniff(&tmp, &confidence, &meta)) {
+ if (!sniff(source, &tmp, &confidence, &meta)) {
ALOGV("FAILED to autodetect media content.");
return NULL;
@@ -263,4 +263,79 @@
return ret;
}
+Mutex MediaExtractor::gSnifferMutex;
+List<MediaExtractor::SnifferFunc> MediaExtractor::gSniffers;
+bool MediaExtractor::gSniffersRegistered = false;
+
+// static
+bool MediaExtractor::sniff(
+ const sp<DataSource> &source, String8 *mimeType, float *confidence, sp<AMessage> *meta) {
+ *mimeType = "";
+ *confidence = 0.0f;
+ meta->clear();
+
+ {
+ Mutex::Autolock autoLock(gSnifferMutex);
+ if (!gSniffersRegistered) {
+ return false;
+ }
+ }
+
+ for (List<SnifferFunc>::iterator it = gSniffers.begin();
+ it != gSniffers.end(); ++it) {
+ String8 newMimeType;
+ float newConfidence;
+ sp<AMessage> newMeta;
+ if ((*it)(source, &newMimeType, &newConfidence, &newMeta)) {
+ if (newConfidence > *confidence) {
+ *mimeType = newMimeType;
+ *confidence = newConfidence;
+ *meta = newMeta;
+ }
+ }
+ }
+
+ return *confidence > 0.0;
+}
+
+// static
+void MediaExtractor::RegisterSniffer_l(SnifferFunc func) {
+ for (List<SnifferFunc>::iterator it = gSniffers.begin();
+ it != gSniffers.end(); ++it) {
+ if (*it == func) {
+ return;
+ }
+ }
+
+ gSniffers.push_back(func);
+}
+
+// static
+void MediaExtractor::RegisterDefaultSniffers() {
+ Mutex::Autolock autoLock(gSnifferMutex);
+ if (gSniffersRegistered) {
+ return;
+ }
+
+ RegisterSniffer_l(SniffMPEG4);
+ RegisterSniffer_l(SniffMatroska);
+ RegisterSniffer_l(SniffOgg);
+ RegisterSniffer_l(SniffWAV);
+ RegisterSniffer_l(SniffFLAC);
+ RegisterSniffer_l(SniffAMR);
+ RegisterSniffer_l(SniffMPEG2TS);
+ RegisterSniffer_l(SniffMP3);
+ RegisterSniffer_l(SniffAAC);
+ RegisterSniffer_l(SniffMPEG2PS);
+ RegisterSniffer_l(SniffMidi);
+
+ char value[PROPERTY_VALUE_MAX];
+ if (property_get("drm.service.enabled", value, NULL)
+ && (!strcmp(value, "1") || !strcasecmp(value, "true"))) {
+ RegisterSniffer_l(SniffDRM);
+ }
+ gSniffersRegistered = true;
+}
+
+
} // namespace android
diff --git a/media/libstagefright/StagefrightMetadataRetriever.cpp b/media/libstagefright/StagefrightMetadataRetriever.cpp
index d8fec5c..5e00c44 100644
--- a/media/libstagefright/StagefrightMetadataRetriever.cpp
+++ b/media/libstagefright/StagefrightMetadataRetriever.cpp
@@ -55,8 +55,6 @@
: mParsedMetaData(false),
mAlbumArt(NULL) {
ALOGV("StagefrightMetadataRetriever()");
-
- DataSource::RegisterDefaultSniffers();
}
StagefrightMetadataRetriever::~StagefrightMetadataRetriever() {
diff --git a/media/libstagefright/filters/MediaFilter.cpp b/media/libstagefright/filters/MediaFilter.cpp
index 877aead..7290193 100644
--- a/media/libstagefright/filters/MediaFilter.cpp
+++ b/media/libstagefright/filters/MediaFilter.cpp
@@ -60,10 +60,6 @@
//////////////////// PUBLIC FUNCTIONS //////////////////////////////////////////
-void MediaFilter::setNotificationMessage(const sp<AMessage> &msg) {
- mNotify = msg;
-}
-
void MediaFilter::initiateAllocateComponent(const sp<AMessage> &msg) {
msg->setWhat(kWhatAllocateComponent);
msg->setTarget(this);
@@ -223,10 +219,7 @@
}
void MediaFilter::signalError(status_t error) {
- sp<AMessage> notify = mNotify->dup();
- notify->setInt32("what", CodecBase::kWhatError);
- notify->setInt32("err", error);
- notify->post();
+ mCallback->onError(error, ACTION_CODE_FATAL);
}
status_t MediaFilter::allocateBuffersOnPort(OMX_U32 portIndex) {
@@ -266,11 +259,6 @@
}
}
- sp<AMessage> notify = mNotify->dup();
- notify->setInt32("what", CodecBase::kWhatBuffersAllocated);
-
- notify->setInt32("portIndex", portIndex);
-
sp<PortDescription> desc = new PortDescription;
for (size_t i = 0; i < mBuffers[portIndex].size(); ++i) {
@@ -278,9 +266,7 @@
desc->addBuffer(info.mBufferID, info.mData);
}
-
- notify->setObject("portDesc", desc);
- notify->post();
+ mCallback->onBuffersAllocated(portIndex, desc);
return OK;
}
@@ -314,20 +300,14 @@
info->mGeneration = mGeneration;
- sp<AMessage> notify = mNotify->dup();
- notify->setInt32("what", CodecBase::kWhatFillThisBuffer);
- notify->setInt32("buffer-id", info->mBufferID);
-
info->mData->meta()->clear();
- notify->setObject("buffer", info->mData);
sp<AMessage> reply = new AMessage(kWhatInputBufferFilled, this);
reply->setInt32("buffer-id", info->mBufferID);
- notify->setMessage("reply", reply);
-
info->mStatus = BufferInfo::OWNED_BY_UPSTREAM;
- notify->post();
+
+ mCallback->fillThisBuffer(info->mBufferID, info->mData, reply);
}
void MediaFilter::postDrainThisBuffer(BufferInfo *info) {
@@ -335,27 +315,17 @@
info->mGeneration = mGeneration;
- sp<AMessage> notify = mNotify->dup();
- notify->setInt32("what", CodecBase::kWhatDrainThisBuffer);
- notify->setInt32("buffer-id", info->mBufferID);
- notify->setInt32("flags", info->mOutputFlags);
- notify->setObject("buffer", info->mData);
-
sp<AMessage> reply = new AMessage(kWhatOutputBufferDrained, this);
reply->setInt32("buffer-id", info->mBufferID);
- notify->setMessage("reply", reply);
-
- notify->post();
+ mCallback->drainThisBuffer(
+ info->mBufferID, info->mData, info->mOutputFlags, reply);
info->mStatus = BufferInfo::OWNED_BY_UPSTREAM;
}
void MediaFilter::postEOS() {
- sp<AMessage> notify = mNotify->dup();
- notify->setInt32("what", CodecBase::kWhatEOS);
- notify->setInt32("err", ERROR_END_OF_STREAM);
- notify->post();
+ mCallback->onEos(ERROR_END_OF_STREAM);
ALOGV("Sent kWhatEOS.");
}
@@ -445,11 +415,8 @@
return;
}
- sp<AMessage> notify = mNotify->dup();
- notify->setInt32("what", kWhatComponentAllocated);
// HACK - need "OMX.google" to use MediaCodec's software renderer
- notify->setString("componentName", "OMX.google.MediaFilter");
- notify->post();
+ mCallback->onComponentAllocated("OMX.google.MediaFilter");
mState = INITIALIZED;
ALOGV("Handled kWhatAllocateComponent.");
}
@@ -526,12 +493,7 @@
mOutputFormat->setInt32("width", mWidth);
mOutputFormat->setInt32("height", mHeight);
- sp<AMessage> notify = mNotify->dup();
- notify->setInt32("what", kWhatComponentConfigured);
- notify->setString("componentName", "MediaFilter");
- notify->setMessage("input-format", mInputFormat);
- notify->setMessage("output-format", mOutputFormat);
- notify->post();
+ mCallback->onComponentConfigured(mInputFormat, mOutputFormat);
mState = CONFIGURED;
ALOGV("Handled kWhatConfigureComponent.");
}
@@ -675,10 +637,11 @@
mState = INITIALIZED;
}
- sp<AMessage> notify = mNotify->dup();
- notify->setInt32("what", keepComponentAllocated ?
- CodecBase::kWhatStopCompleted : CodecBase::kWhatReleaseCompleted);
- notify->post();
+ if (keepComponentAllocated) {
+ mCallback->onStopCompleted();
+ } else {
+ mCallback->onReleaseCompleted();
+ }
}
void MediaFilter::onFlush() {
@@ -700,9 +663,7 @@
mPortEOS[kPortIndexOutput] = false;
mInputEOSResult = OK;
- sp<AMessage> notify = mNotify->dup();
- notify->setInt32("what", CodecBase::kWhatFlushCompleted);
- notify->post();
+ mCallback->onFlushCompleted();
ALOGV("Posted kWhatFlushCompleted");
// MediaCodec returns all input buffers after flush, so in
@@ -734,13 +695,10 @@
return;
}
- sp<AMessage> reply = mNotify->dup();
- reply->setInt32("what", CodecBase::kWhatInputSurfaceCreated);
- reply->setObject(
- "input-surface",
+ mCallback->onInputSurfaceCreated(
+ nullptr, nullptr,
new BufferProducerWrapper(
mGraphicBufferListener->getIGraphicBufferProducer()));
- reply->post();
}
void MediaFilter::onInputFrameAvailable() {
@@ -802,9 +760,7 @@
}
mPortEOS[kPortIndexOutput] = true;
- sp<AMessage> notify = mNotify->dup();
- notify->setInt32("what", CodecBase::kWhatSignaledInputEOS);
- notify->post();
+ mCallback->onSignaledInputEOS(OK);
ALOGV("Output stream saw EOS.");
}
diff --git a/media/libstagefright/id3/testid3.cpp b/media/libstagefright/id3/testid3.cpp
index b2f4188..442a3ff 100644
--- a/media/libstagefright/id3/testid3.cpp
+++ b/media/libstagefright/id3/testid3.cpp
@@ -154,8 +154,6 @@
int main(int argc, char **argv) {
android::ProcessState::self()->startThreadPool();
- DataSource::RegisterDefaultSniffers();
-
for (int i = 1; i < argc; ++i) {
scan(argv[i]);
}
diff --git a/media/libstagefright/omx/tests/OMXHarness.cpp b/media/libstagefright/omx/tests/OMXHarness.cpp
index 935d7bf..1ce5d1a 100644
--- a/media/libstagefright/omx/tests/OMXHarness.cpp
+++ b/media/libstagefright/omx/tests/OMXHarness.cpp
@@ -800,7 +800,6 @@
using namespace android;
android::ProcessState::self()->startThreadPool();
- DataSource::RegisterDefaultSniffers();
const char *me = argv[0];
diff --git a/media/libstagefright/rtsp/rtp_test.cpp b/media/libstagefright/rtsp/rtp_test.cpp
index 24f529b..e612a8d 100644
--- a/media/libstagefright/rtsp/rtp_test.cpp
+++ b/media/libstagefright/rtsp/rtp_test.cpp
@@ -37,8 +37,6 @@
int main(int argc, char **argv) {
android::ProcessState::self()->startThreadPool();
- DataSource::RegisterDefaultSniffers();
-
const char *rtpFilename = NULL;
const char *rtcpFilename = NULL;
diff --git a/media/libstagefright/wifi-display/source/PlaybackSession.cpp b/media/libstagefright/wifi-display/source/PlaybackSession.cpp
index 3587cb9..f1ecca0 100644
--- a/media/libstagefright/wifi-display/source/PlaybackSession.cpp
+++ b/media/libstagefright/wifi-display/source/PlaybackSession.cpp
@@ -36,7 +36,6 @@
#include <media/stagefright/foundation/AMessage.h>
#include <media/stagefright/foundation/hexdump.h>
#include <media/stagefright/AudioSource.h>
-#include <media/stagefright/DataSource.h>
#include <media/stagefright/MediaDefs.h>
#include <media/stagefright/MediaErrors.h>
#include <media/stagefright/MediaSource.h>
@@ -748,8 +747,6 @@
status_t WifiDisplaySource::PlaybackSession::setupMediaPacketizer(
bool enableAudio, bool enableVideo) {
- DataSource::RegisterDefaultSniffers();
-
mExtractor = new NuMediaExtractor;
status_t err = mExtractor->setDataSource(
diff --git a/services/audioflinger/Effects.cpp b/services/audioflinger/Effects.cpp
index ec9ced2..f5e4f35 100644
--- a/services/audioflinger/Effects.cpp
+++ b/services/audioflinger/Effects.cpp
@@ -599,16 +599,17 @@
return mStatus;
}
if (cmdCode == EFFECT_CMD_GET_PARAM &&
- (*replySize < sizeof(effect_param_t) ||
- ((effect_param_t *)pCmdData)->psize > *replySize - sizeof(effect_param_t))) {
- android_errorWriteLog(0x534e4554, "29251553");
- return -EINVAL;
- }
- if (cmdCode == EFFECT_CMD_GET_PARAM &&
(sizeof(effect_param_t) > cmdSize ||
((effect_param_t *)pCmdData)->psize > cmdSize
- sizeof(effect_param_t))) {
android_errorWriteLog(0x534e4554, "32438594");
+ android_errorWriteLog(0x534e4554, "33003822");
+ return -EINVAL;
+ }
+ if (cmdCode == EFFECT_CMD_GET_PARAM &&
+ (*replySize < sizeof(effect_param_t) ||
+ ((effect_param_t *)pCmdData)->psize > *replySize - sizeof(effect_param_t))) {
+ android_errorWriteLog(0x534e4554, "29251553");
return -EINVAL;
}
if ((cmdCode == EFFECT_CMD_SET_PARAM
diff --git a/services/audiopolicy/Android.mk b/services/audiopolicy/Android.mk
index 3fb545d..9f3488d 100644
--- a/services/audiopolicy/Android.mk
+++ b/services/audiopolicy/Android.mk
@@ -4,19 +4,9 @@
LOCAL_SRC_FILES:= \
service/AudioPolicyService.cpp \
- service/AudioPolicyEffects.cpp
-
-ifeq ($(USE_LEGACY_AUDIO_POLICY), 1)
-LOCAL_SRC_FILES += \
- service/AudioPolicyInterfaceImplLegacy.cpp \
- service/AudioPolicyClientImplLegacy.cpp
-
- LOCAL_CFLAGS += -DUSE_LEGACY_AUDIO_POLICY
-else
-LOCAL_SRC_FILES += \
+ service/AudioPolicyEffects.cpp \
service/AudioPolicyInterfaceImpl.cpp \
service/AudioPolicyClientImpl.cpp
-endif
LOCAL_C_INCLUDES := \
$(TOPDIR)frameworks/av/services/audioflinger \
@@ -32,12 +22,8 @@
libbinder \
libaudioclient \
libhardware_legacy \
- libserviceutility
-
-ifneq ($(USE_LEGACY_AUDIO_POLICY), 1)
-LOCAL_SHARED_LIBRARIES += \
+ libserviceutility \
libaudiopolicymanager
-endif
LOCAL_STATIC_LIBRARIES := \
libmedia_helper \
@@ -52,8 +38,6 @@
include $(BUILD_SHARED_LIBRARY)
-ifneq ($(USE_LEGACY_AUDIO_POLICY), 1)
-
include $(CLEAR_VARS)
LOCAL_SRC_FILES:= managerdefault/AudioPolicyManager.cpp
@@ -136,7 +120,6 @@
include $(BUILD_SHARED_LIBRARY)
endif
-endif
#######################################################################
# Recursive call sub-folder Android.mk
diff --git a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
index 5ef0216..a714041 100644
--- a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
+++ b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
@@ -4477,9 +4477,7 @@
bool AudioPolicyManager::streamsMatchForvolume(audio_stream_type_t stream1,
audio_stream_type_t stream2) {
- return ((stream1 == stream2) ||
- ((stream1 == AUDIO_STREAM_ACCESSIBILITY) && (stream2 == AUDIO_STREAM_MUSIC)) ||
- ((stream1 == AUDIO_STREAM_MUSIC) && (stream2 == AUDIO_STREAM_ACCESSIBILITY)));
+ return (stream1 == stream2);
}
uint32_t AudioPolicyManager::getStrategyForStream(audio_stream_type_t stream) {
diff --git a/services/audiopolicy/service/AudioPolicyClientImplLegacy.cpp b/services/audiopolicy/service/AudioPolicyClientImplLegacy.cpp
deleted file mode 100644
index aa228aa..0000000
--- a/services/audiopolicy/service/AudioPolicyClientImplLegacy.cpp
+++ /dev/null
@@ -1,316 +0,0 @@
-/*
- * Copyright (C) 2009 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#define LOG_TAG "AudioPolicyService"
-//#define LOG_NDEBUG 0
-
-#include "Configuration.h"
-#undef __STRICT_ANSI__
-#define __STDINT_LIMITS
-#define __STDC_LIMIT_MACROS
-#include <stdint.h>
-
-#include <sys/time.h>
-#include <binder/IServiceManager.h>
-#include <utils/Log.h>
-#include <cutils/properties.h>
-#include <binder/IPCThreadState.h>
-#include <utils/String16.h>
-#include <utils/threads.h>
-#include "AudioPolicyService.h"
-#include "ServiceUtilities.h"
-#include <hardware_legacy/power.h>
-#include <media/AudioEffect.h>
-//#include <media/IAudioFlinger.h>
-
-#include <hardware/hardware.h>
-#include <system/audio.h>
-#include <system/audio_policy.h>
-#include <hardware/audio_policy.h>
-#include <audio_effects/audio_effects_conf.h>
-#include <media/AudioParameter.h>
-
-
-namespace android {
-
-/* implementation of the interface to the policy manager */
-extern "C" {
-
-audio_module_handle_t aps_load_hw_module(void *service __unused,
- const char *name)
-{
- sp<IAudioFlinger> af = AudioSystem::get_audio_flinger();
- if (af == 0) {
- ALOGW("%s: could not get AudioFlinger", __func__);
- return AUDIO_MODULE_HANDLE_NONE;
- }
-
- return af->loadHwModule(name);
-}
-
-static audio_io_handle_t open_output(audio_module_handle_t module,
- audio_devices_t *pDevices,
- uint32_t *pSamplingRate,
- audio_format_t *pFormat,
- audio_channel_mask_t *pChannelMask,
- uint32_t *pLatencyMs,
- audio_output_flags_t flags,
- const audio_offload_info_t *offloadInfo)
-{
- sp<IAudioFlinger> af = AudioSystem::get_audio_flinger();
- if (af == 0) {
- ALOGW("%s: could not get AudioFlinger", __func__);
- return AUDIO_IO_HANDLE_NONE;
- }
-
- if (pSamplingRate == NULL || pFormat == NULL || pChannelMask == NULL ||
- pDevices == NULL || pLatencyMs == NULL) {
- return AUDIO_IO_HANDLE_NONE;
- }
- audio_config_t config = AUDIO_CONFIG_INITIALIZER;
- config.sample_rate = *pSamplingRate;
- config.format = *pFormat;
- config.channel_mask = *pChannelMask;
- if (offloadInfo != NULL) {
- config.offload_info = *offloadInfo;
- }
- audio_io_handle_t output = AUDIO_IO_HANDLE_NONE;
- status_t status = af->openOutput(module, &output, &config, pDevices,
- String8(""), pLatencyMs, flags);
- if (status == NO_ERROR) {
- *pSamplingRate = config.sample_rate;
- *pFormat = config.format;
- *pChannelMask = config.channel_mask;
- if (offloadInfo != NULL) {
- *((audio_offload_info_t *)offloadInfo) = config.offload_info;
- }
- }
- return output;
-}
-
-// deprecated: replaced by aps_open_output_on_module()
-audio_io_handle_t aps_open_output(void *service __unused,
- audio_devices_t *pDevices,
- uint32_t *pSamplingRate,
- audio_format_t *pFormat,
- audio_channel_mask_t *pChannelMask,
- uint32_t *pLatencyMs,
- audio_output_flags_t flags)
-{
- return open_output(AUDIO_MODULE_HANDLE_NONE, pDevices, pSamplingRate, pFormat, pChannelMask,
- pLatencyMs, flags, NULL);
-}
-
-audio_io_handle_t aps_open_output_on_module(void *service __unused,
- audio_module_handle_t module,
- audio_devices_t *pDevices,
- uint32_t *pSamplingRate,
- audio_format_t *pFormat,
- audio_channel_mask_t *pChannelMask,
- uint32_t *pLatencyMs,
- audio_output_flags_t flags,
- const audio_offload_info_t *offloadInfo)
-{
- return open_output(module, pDevices, pSamplingRate, pFormat, pChannelMask,
- pLatencyMs, flags, offloadInfo);
-}
-
-audio_io_handle_t aps_open_dup_output(void *service __unused,
- audio_io_handle_t output1,
- audio_io_handle_t output2)
-{
- sp<IAudioFlinger> af = AudioSystem::get_audio_flinger();
- if (af == 0) {
- ALOGW("%s: could not get AudioFlinger", __func__);
- return 0;
- }
- return af->openDuplicateOutput(output1, output2);
-}
-
-int aps_close_output(void *service __unused, audio_io_handle_t output)
-{
- sp<IAudioFlinger> af = AudioSystem::get_audio_flinger();
- if (af == 0) {
- return PERMISSION_DENIED;
- }
-
- return af->closeOutput(output);
-}
-
-int aps_suspend_output(void *service __unused, audio_io_handle_t output)
-{
- sp<IAudioFlinger> af = AudioSystem::get_audio_flinger();
- if (af == 0) {
- ALOGW("%s: could not get AudioFlinger", __func__);
- return PERMISSION_DENIED;
- }
-
- return af->suspendOutput(output);
-}
-
-int aps_restore_output(void *service __unused, audio_io_handle_t output)
-{
- sp<IAudioFlinger> af = AudioSystem::get_audio_flinger();
- if (af == 0) {
- ALOGW("%s: could not get AudioFlinger", __func__);
- return PERMISSION_DENIED;
- }
-
- return af->restoreOutput(output);
-}
-
-static audio_io_handle_t open_input(audio_module_handle_t module,
- audio_devices_t *pDevices,
- uint32_t *pSamplingRate,
- audio_format_t *pFormat,
- audio_channel_mask_t *pChannelMask)
-{
- sp<IAudioFlinger> af = AudioSystem::get_audio_flinger();
- if (af == 0) {
- ALOGW("%s: could not get AudioFlinger", __func__);
- return AUDIO_IO_HANDLE_NONE;
- }
-
- if (pSamplingRate == NULL || pFormat == NULL || pChannelMask == NULL || pDevices == NULL) {
- return AUDIO_IO_HANDLE_NONE;
- }
-
- if (((*pDevices & AUDIO_DEVICE_IN_REMOTE_SUBMIX) == AUDIO_DEVICE_IN_REMOTE_SUBMIX)
- && !captureAudioOutputAllowed(IPCThreadState::self()->getCallingPid(),
- IPCThreadState::self()->getCallingUid())) {
- ALOGE("open_input() permission denied: capture not allowed");
- return AUDIO_IO_HANDLE_NONE;
- }
-
- audio_config_t config = AUDIO_CONFIG_INITIALIZER;;
- config.sample_rate = *pSamplingRate;
- config.format = *pFormat;
- config.channel_mask = *pChannelMask;
- audio_io_handle_t input = AUDIO_IO_HANDLE_NONE;
- status_t status = af->openInput(module, &input, &config, pDevices,
- String8(""), AUDIO_SOURCE_MIC, AUDIO_INPUT_FLAG_FAST /*FIXME*/);
- if (status == NO_ERROR) {
- *pSamplingRate = config.sample_rate;
- *pFormat = config.format;
- *pChannelMask = config.channel_mask;
- }
- return input;
-}
-
-
-// deprecated: replaced by aps_open_input_on_module(), and acoustics parameter is ignored
-audio_io_handle_t aps_open_input(void *service __unused,
- audio_devices_t *pDevices,
- uint32_t *pSamplingRate,
- audio_format_t *pFormat,
- audio_channel_mask_t *pChannelMask,
- audio_in_acoustics_t acoustics __unused)
-{
- return open_input(AUDIO_MODULE_HANDLE_NONE, pDevices, pSamplingRate, pFormat, pChannelMask);
-}
-
-audio_io_handle_t aps_open_input_on_module(void *service __unused,
- audio_module_handle_t module,
- audio_devices_t *pDevices,
- uint32_t *pSamplingRate,
- audio_format_t *pFormat,
- audio_channel_mask_t *pChannelMask)
-{
- return open_input(module, pDevices, pSamplingRate, pFormat, pChannelMask);
-}
-
-int aps_close_input(void *service __unused, audio_io_handle_t input)
-{
- sp<IAudioFlinger> af = AudioSystem::get_audio_flinger();
- if (af == 0) {
- return PERMISSION_DENIED;
- }
-
- return af->closeInput(input);
-}
-
-int aps_invalidate_stream(void *service __unused, audio_stream_type_t stream)
-{
- sp<IAudioFlinger> af = AudioSystem::get_audio_flinger();
- if (af == 0) {
- return PERMISSION_DENIED;
- }
-
- return af->invalidateStream(stream);
-}
-
-int aps_move_effects(void *service __unused, audio_session_t session,
- audio_io_handle_t src_output,
- audio_io_handle_t dst_output)
-{
- sp<IAudioFlinger> af = AudioSystem::get_audio_flinger();
- if (af == 0) {
- return PERMISSION_DENIED;
- }
-
- return af->moveEffects(session, src_output, dst_output);
-}
-
-char * aps_get_parameters(void *service __unused, audio_io_handle_t io_handle,
- const char *keys)
-{
- String8 result = AudioSystem::getParameters(io_handle, String8(keys));
- return strdup(result.string());
-}
-
-void aps_set_parameters(void *service, audio_io_handle_t io_handle,
- const char *kv_pairs, int delay_ms)
-{
- AudioPolicyService *audioPolicyService = (AudioPolicyService *)service;
-
- audioPolicyService->setParameters(io_handle, kv_pairs, delay_ms);
-}
-
-int aps_set_stream_volume(void *service, audio_stream_type_t stream,
- float volume, audio_io_handle_t output,
- int delay_ms)
-{
- AudioPolicyService *audioPolicyService = (AudioPolicyService *)service;
-
- return audioPolicyService->setStreamVolume(stream, volume, output,
- delay_ms);
-}
-
-int aps_start_tone(void *service, audio_policy_tone_t tone,
- audio_stream_type_t stream)
-{
- AudioPolicyService *audioPolicyService = (AudioPolicyService *)service;
-
- return audioPolicyService->startTone(tone, stream);
-}
-
-int aps_stop_tone(void *service)
-{
- AudioPolicyService *audioPolicyService = (AudioPolicyService *)service;
-
- return audioPolicyService->stopTone();
-}
-
-int aps_set_voice_volume(void *service, float volume, int delay_ms)
-{
- AudioPolicyService *audioPolicyService = (AudioPolicyService *)service;
-
- return audioPolicyService->setVoiceVolume(volume, delay_ms);
-}
-
-}; // extern "C"
-
-}; // namespace android
diff --git a/services/audiopolicy/service/AudioPolicyInterfaceImplLegacy.cpp b/services/audiopolicy/service/AudioPolicyInterfaceImplLegacy.cpp
deleted file mode 100644
index a5b96fe..0000000
--- a/services/audiopolicy/service/AudioPolicyInterfaceImplLegacy.cpp
+++ /dev/null
@@ -1,633 +0,0 @@
-/*
- * Copyright (C) 2009 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#define LOG_TAG "AudioPolicyService"
-//#define LOG_NDEBUG 0
-
-#include <utils/Log.h>
-#include "AudioPolicyService.h"
-#include "ServiceUtilities.h"
-
-#include <system/audio.h>
-#include <system/audio_policy.h>
-#include <hardware/audio_policy.h>
-#include <media/AudioPolicyHelper.h>
-
-namespace android {
-
-
-// ----------------------------------------------------------------------------
-
-status_t AudioPolicyService::setDeviceConnectionState(audio_devices_t device,
- audio_policy_dev_state_t state,
- const char *device_address,
- const char *device_name __unused)
-{
- if (mpAudioPolicy == NULL) {
- return NO_INIT;
- }
- if (!settingsAllowed()) {
- return PERMISSION_DENIED;
- }
- if (!audio_is_output_device(device) && !audio_is_input_device(device)) {
- return BAD_VALUE;
- }
- if (state != AUDIO_POLICY_DEVICE_STATE_AVAILABLE &&
- state != AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE) {
- return BAD_VALUE;
- }
-
- ALOGV("setDeviceConnectionState()");
- Mutex::Autolock _l(mLock);
- return mpAudioPolicy->set_device_connection_state(mpAudioPolicy, device,
- state, device_address);
-}
-
-audio_policy_dev_state_t AudioPolicyService::getDeviceConnectionState(
- audio_devices_t device,
- const char *device_address)
-{
- if (mpAudioPolicy == NULL) {
- return AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE;
- }
- return mpAudioPolicy->get_device_connection_state(mpAudioPolicy, device,
- device_address);
-}
-
-status_t AudioPolicyService::setPhoneState(audio_mode_t state)
-{
- if (mpAudioPolicy == NULL) {
- return NO_INIT;
- }
- if (!settingsAllowed()) {
- return PERMISSION_DENIED;
- }
- if (uint32_t(state) >= AUDIO_MODE_CNT) {
- return BAD_VALUE;
- }
-
- ALOGV("setPhoneState()");
-
- // TODO: check if it is more appropriate to do it in platform specific policy manager
- AudioSystem::setMode(state);
-
- Mutex::Autolock _l(mLock);
- mpAudioPolicy->set_phone_state(mpAudioPolicy, state);
- mPhoneState = state;
- return NO_ERROR;
-}
-
-audio_mode_t AudioPolicyService::getPhoneState()
-{
- Mutex::Autolock _l(mLock);
- return mPhoneState;
-}
-
-status_t AudioPolicyService::setForceUse(audio_policy_force_use_t usage,
- audio_policy_forced_cfg_t config)
-{
- if (mpAudioPolicy == NULL) {
- return NO_INIT;
- }
- if (!settingsAllowed()) {
- return PERMISSION_DENIED;
- }
- if (usage < 0 || usage >= AUDIO_POLICY_FORCE_USE_CNT) {
- return BAD_VALUE;
- }
- if (config < 0 || config >= AUDIO_POLICY_FORCE_CFG_CNT) {
- return BAD_VALUE;
- }
- ALOGV("setForceUse()");
- Mutex::Autolock _l(mLock);
- mpAudioPolicy->set_force_use(mpAudioPolicy, usage, config);
- return NO_ERROR;
-}
-
-audio_policy_forced_cfg_t AudioPolicyService::getForceUse(audio_policy_force_use_t usage)
-{
- if (mpAudioPolicy == NULL) {
- return AUDIO_POLICY_FORCE_NONE;
- }
- if (usage < 0 || usage >= AUDIO_POLICY_FORCE_USE_CNT) {
- return AUDIO_POLICY_FORCE_NONE;
- }
- return mpAudioPolicy->get_force_use(mpAudioPolicy, usage);
-}
-
-audio_io_handle_t AudioPolicyService::getOutput(audio_stream_type_t stream,
- uint32_t samplingRate,
- audio_format_t format,
- audio_channel_mask_t channelMask,
- audio_output_flags_t flags,
- const audio_offload_info_t *offloadInfo)
-{
- if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) {
- return AUDIO_IO_HANDLE_NONE;
- }
- if (mpAudioPolicy == NULL) {
- return AUDIO_IO_HANDLE_NONE;
- }
- ALOGV("getOutput()");
- Mutex::Autolock _l(mLock);
- return mpAudioPolicy->get_output(mpAudioPolicy, stream, samplingRate,
- format, channelMask, flags, offloadInfo);
-}
-
-status_t AudioPolicyService::startOutput(audio_io_handle_t output,
- audio_stream_type_t stream,
- audio_session_t session)
-{
- if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) {
- return BAD_VALUE;
- }
- if (mpAudioPolicy == NULL) {
- return NO_INIT;
- }
- ALOGV("startOutput()");
- // create audio processors according to stream
- sp<AudioPolicyEffects>audioPolicyEffects;
- {
- Mutex::Autolock _l(mLock);
- audioPolicyEffects = mAudioPolicyEffects;
- }
- if (audioPolicyEffects != 0) {
- status_t status = audioPolicyEffects->addOutputSessionEffects(output, stream, session);
- if (status != NO_ERROR && status != ALREADY_EXISTS) {
- ALOGW("Failed to add effects on session %d", session);
- }
- }
-
- Mutex::Autolock _l(mLock);
- return mpAudioPolicy->start_output(mpAudioPolicy, output, stream, session);
-}
-
-status_t AudioPolicyService::stopOutput(audio_io_handle_t output,
- audio_stream_type_t stream,
- audio_session_t session)
-{
- if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) {
- return BAD_VALUE;
- }
- if (mpAudioPolicy == NULL) {
- return NO_INIT;
- }
- ALOGV("stopOutput()");
- mOutputCommandThread->stopOutputCommand(output, stream, session);
- return NO_ERROR;
-}
-
-status_t AudioPolicyService::doStopOutput(audio_io_handle_t output,
- audio_stream_type_t stream,
- audio_session_t session)
-{
- ALOGV("doStopOutput from tid %d", gettid());
- // release audio processors from the stream
- sp<AudioPolicyEffects>audioPolicyEffects;
- {
- Mutex::Autolock _l(mLock);
- audioPolicyEffects = mAudioPolicyEffects;
- }
- if (audioPolicyEffects != 0) {
- status_t status = audioPolicyEffects->releaseOutputSessionEffects(output, stream, session);
- if (status != NO_ERROR && status != ALREADY_EXISTS) {
- ALOGW("Failed to release effects on session %d", session);
- }
- }
- Mutex::Autolock _l(mLock);
- return mpAudioPolicy->stop_output(mpAudioPolicy, output, stream, session);
-}
-
-void AudioPolicyService::releaseOutput(audio_io_handle_t output,
- audio_stream_type_t stream,
- audio_session_t session)
-{
- if (mpAudioPolicy == NULL) {
- return;
- }
- ALOGV("releaseOutput()");
- mOutputCommandThread->releaseOutputCommand(output, stream, session);
-}
-
-void AudioPolicyService::doReleaseOutput(audio_io_handle_t output,
- audio_stream_type_t stream __unused,
- audio_session_t session __unused)
-{
- ALOGV("doReleaseOutput from tid %d", gettid());
- Mutex::Autolock _l(mLock);
- mpAudioPolicy->release_output(mpAudioPolicy, output);
-}
-
-status_t AudioPolicyService::getInputForAttr(const audio_attributes_t *attr,
- audio_io_handle_t *input,
- audio_session_t session,
- pid_t pid __unused,
- uid_t uid __unused,
- uint32_t samplingRate,
- audio_format_t format,
- audio_channel_mask_t channelMask,
- audio_input_flags_t flags __unused,
- audio_port_handle_t selectedDeviceId __unused)
-{
- if (mpAudioPolicy == NULL) {
- return NO_INIT;
- }
-
- audio_source_t inputSource = attr->source;
-
- // already checked by client, but double-check in case the client wrapper is bypassed
- if (inputSource >= AUDIO_SOURCE_CNT && inputSource != AUDIO_SOURCE_HOTWORD &&
- inputSource != AUDIO_SOURCE_FM_TUNER) {
- return BAD_VALUE;
- }
-
- if (inputSource == AUDIO_SOURCE_DEFAULT) {
- inputSource = AUDIO_SOURCE_MIC;
- }
-
- if ((inputSource == AUDIO_SOURCE_HOTWORD) && !captureHotwordAllowed()) {
- return BAD_VALUE;
- }
-
- sp<AudioPolicyEffects>audioPolicyEffects;
- {
- Mutex::Autolock _l(mLock);
- // the audio_in_acoustics_t parameter is ignored by get_input()
- *input = mpAudioPolicy->get_input(mpAudioPolicy, inputSource, samplingRate,
- format, channelMask, (audio_in_acoustics_t) 0);
- audioPolicyEffects = mAudioPolicyEffects;
- }
- if (*input == AUDIO_IO_HANDLE_NONE) {
- return INVALID_OPERATION;
- }
-
- if (audioPolicyEffects != 0) {
- // create audio pre processors according to input source
- status_t status = audioPolicyEffects->addInputEffects(*input, inputSource, session);
- if (status != NO_ERROR && status != ALREADY_EXISTS) {
- ALOGW("Failed to add effects on input %d", input);
- }
- }
- return NO_ERROR;
-}
-
-status_t AudioPolicyService::startInput(audio_io_handle_t input,
- audio_session_t session __unused)
-{
- if (mpAudioPolicy == NULL) {
- return NO_INIT;
- }
- Mutex::Autolock _l(mLock);
-
- return mpAudioPolicy->start_input(mpAudioPolicy, input);
-}
-
-status_t AudioPolicyService::stopInput(audio_io_handle_t input,
- audio_session_t session __unused)
-{
- if (mpAudioPolicy == NULL) {
- return NO_INIT;
- }
- Mutex::Autolock _l(mLock);
-
- return mpAudioPolicy->stop_input(mpAudioPolicy, input);
-}
-
-void AudioPolicyService::releaseInput(audio_io_handle_t input,
- audio_session_t session)
-{
- if (mpAudioPolicy == NULL) {
- return;
- }
-
- sp<AudioPolicyEffects>audioPolicyEffects;
- {
- Mutex::Autolock _l(mLock);
- mpAudioPolicy->release_input(mpAudioPolicy, input);
- audioPolicyEffects = mAudioPolicyEffects;
- }
- if (audioPolicyEffects != 0) {
- // release audio processors from the input
- status_t status = audioPolicyEffects->releaseInputEffects(input, session);
- if(status != NO_ERROR) {
- ALOGW("Failed to release effects on input %d", input);
- }
- }
-}
-
-status_t AudioPolicyService::initStreamVolume(audio_stream_type_t stream,
- int indexMin,
- int indexMax)
-{
- if (mpAudioPolicy == NULL) {
- return NO_INIT;
- }
- if (!settingsAllowed()) {
- return PERMISSION_DENIED;
- }
- if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) {
- return BAD_VALUE;
- }
- Mutex::Autolock _l(mLock);
- mpAudioPolicy->init_stream_volume(mpAudioPolicy, stream, indexMin, indexMax);
- return NO_ERROR;
-}
-
-status_t AudioPolicyService::setStreamVolumeIndex(audio_stream_type_t stream,
- int index,
- audio_devices_t device)
-{
- if (mpAudioPolicy == NULL) {
- return NO_INIT;
- }
- if (!settingsAllowed()) {
- return PERMISSION_DENIED;
- }
- if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) {
- return BAD_VALUE;
- }
- Mutex::Autolock _l(mLock);
- if (mpAudioPolicy->set_stream_volume_index_for_device) {
- return mpAudioPolicy->set_stream_volume_index_for_device(mpAudioPolicy,
- stream,
- index,
- device);
- } else {
- return mpAudioPolicy->set_stream_volume_index(mpAudioPolicy, stream, index);
- }
-}
-
-status_t AudioPolicyService::getStreamVolumeIndex(audio_stream_type_t stream,
- int *index,
- audio_devices_t device)
-{
- if (mpAudioPolicy == NULL) {
- return NO_INIT;
- }
- if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) {
- return BAD_VALUE;
- }
- Mutex::Autolock _l(mLock);
- if (mpAudioPolicy->get_stream_volume_index_for_device) {
- return mpAudioPolicy->get_stream_volume_index_for_device(mpAudioPolicy,
- stream,
- index,
- device);
- } else {
- return mpAudioPolicy->get_stream_volume_index(mpAudioPolicy, stream, index);
- }
-}
-
-uint32_t AudioPolicyService::getStrategyForStream(audio_stream_type_t stream)
-{
- if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) {
- return 0;
- }
- if (mpAudioPolicy == NULL) {
- return 0;
- }
- return mpAudioPolicy->get_strategy_for_stream(mpAudioPolicy, stream);
-}
-
-//audio policy: use audio_device_t appropriately
-
-audio_devices_t AudioPolicyService::getDevicesForStream(audio_stream_type_t stream)
-{
- if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) {
- return AUDIO_DEVICE_NONE;
- }
- if (mpAudioPolicy == NULL) {
- return AUDIO_DEVICE_NONE;
- }
- return mpAudioPolicy->get_devices_for_stream(mpAudioPolicy, stream);
-}
-
-audio_io_handle_t AudioPolicyService::getOutputForEffect(const effect_descriptor_t *desc)
-{
- // FIXME change return type to status_t, and return NO_INIT here
- if (mpAudioPolicy == NULL) {
- return 0;
- }
- Mutex::Autolock _l(mLock);
- return mpAudioPolicy->get_output_for_effect(mpAudioPolicy, desc);
-}
-
-status_t AudioPolicyService::registerEffect(const effect_descriptor_t *desc,
- audio_io_handle_t io,
- uint32_t strategy,
- audio_session_t session,
- int id)
-{
- if (mpAudioPolicy == NULL) {
- return NO_INIT;
- }
- return mpAudioPolicy->register_effect(mpAudioPolicy, desc, io, strategy, session, id);
-}
-
-status_t AudioPolicyService::unregisterEffect(int id)
-{
- if (mpAudioPolicy == NULL) {
- return NO_INIT;
- }
- return mpAudioPolicy->unregister_effect(mpAudioPolicy, id);
-}
-
-status_t AudioPolicyService::setEffectEnabled(int id, bool enabled)
-{
- if (mpAudioPolicy == NULL) {
- return NO_INIT;
- }
- return mpAudioPolicy->set_effect_enabled(mpAudioPolicy, id, enabled);
-}
-
-bool AudioPolicyService::isStreamActive(audio_stream_type_t stream, uint32_t inPastMs) const
-{
- if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) {
- return false;
- }
- if (mpAudioPolicy == NULL) {
- return false;
- }
- Mutex::Autolock _l(mLock);
- return mpAudioPolicy->is_stream_active(mpAudioPolicy, stream, inPastMs);
-}
-
-bool AudioPolicyService::isStreamActiveRemotely(audio_stream_type_t stream, uint32_t inPastMs) const
-{
- if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) {
- return false;
- }
- if (mpAudioPolicy == NULL) {
- return false;
- }
- Mutex::Autolock _l(mLock);
- return mpAudioPolicy->is_stream_active_remotely(mpAudioPolicy, stream, inPastMs);
-}
-
-bool AudioPolicyService::isSourceActive(audio_source_t source) const
-{
- if (mpAudioPolicy == NULL) {
- return false;
- }
- if (mpAudioPolicy->is_source_active == 0) {
- return false;
- }
- Mutex::Autolock _l(mLock);
- return mpAudioPolicy->is_source_active(mpAudioPolicy, source);
-}
-
-status_t AudioPolicyService::queryDefaultPreProcessing(audio_session_t audioSession,
- effect_descriptor_t *descriptors,
- uint32_t *count)
-{
- if (mpAudioPolicy == NULL) {
- *count = 0;
- return NO_INIT;
- }
- sp<AudioPolicyEffects>audioPolicyEffects;
- {
- Mutex::Autolock _l(mLock);
- audioPolicyEffects = mAudioPolicyEffects;
- }
- if (audioPolicyEffects == 0) {
- *count = 0;
- return NO_INIT;
- }
- return audioPolicyEffects->queryDefaultInputEffects(audioSession, descriptors, count);
-}
-
-bool AudioPolicyService::isOffloadSupported(const audio_offload_info_t& info)
-{
- if (mpAudioPolicy == NULL) {
- ALOGV("mpAudioPolicy == NULL");
- return false;
- }
-
- if (mpAudioPolicy->is_offload_supported == NULL) {
- ALOGV("HAL does not implement is_offload_supported");
- return false;
- }
-
- return mpAudioPolicy->is_offload_supported(mpAudioPolicy, &info);
-}
-
-status_t AudioPolicyService::listAudioPorts(audio_port_role_t role __unused,
- audio_port_type_t type __unused,
- unsigned int *num_ports,
- struct audio_port *ports __unused,
- unsigned int *generation __unused)
-{
- *num_ports = 0;
- return INVALID_OPERATION;
-}
-
-status_t AudioPolicyService::getAudioPort(struct audio_port *port __unused)
-{
- return INVALID_OPERATION;
-}
-
-status_t AudioPolicyService::createAudioPatch(const struct audio_patch *patch __unused,
- audio_patch_handle_t *handle __unused)
-{
- return INVALID_OPERATION;
-}
-
-status_t AudioPolicyService::releaseAudioPatch(audio_patch_handle_t handle __unused)
-{
- return INVALID_OPERATION;
-}
-
-status_t AudioPolicyService::listAudioPatches(unsigned int *num_patches,
- struct audio_patch *patches __unused,
- unsigned int *generation __unused)
-{
- *num_patches = 0;
- return INVALID_OPERATION;
-}
-
-status_t AudioPolicyService::setAudioPortConfig(const struct audio_port_config *config __unused)
-{
- return INVALID_OPERATION;
-}
-
-status_t AudioPolicyService::getOutputForAttr(const audio_attributes_t *attr,
- audio_io_handle_t *output,
- audio_session_t session __unused,
- audio_stream_type_t *stream,
- uid_t uid __unused,
- uint32_t samplingRate,
- audio_format_t format,
- audio_channel_mask_t channelMask,
- audio_output_flags_t flags,
- audio_port_handle_t selectedDeviceId __unused,
- const audio_offload_info_t *offloadInfo)
-{
- if (attr != NULL) {
- *stream = audio_attributes_to_stream_type(attr);
- } else {
- if (*stream == AUDIO_STREAM_DEFAULT) {
- return BAD_VALUE;
- }
- }
- *output = getOutput(*stream, samplingRate, format, channelMask,
- flags, offloadInfo);
- if (*output == AUDIO_IO_HANDLE_NONE) {
- return INVALID_OPERATION;
- }
- return NO_ERROR;
-}
-
-status_t AudioPolicyService::acquireSoundTriggerSession(audio_session_t *session __unused,
- audio_io_handle_t *ioHandle __unused,
- audio_devices_t *device __unused)
-{
- return INVALID_OPERATION;
-}
-
-status_t AudioPolicyService::releaseSoundTriggerSession(audio_session_t session __unused)
-{
- return INVALID_OPERATION;
-}
-
-status_t AudioPolicyService::registerPolicyMixes(const Vector<AudioMix>& mixes __unused,
- bool registration __unused)
-{
- return INVALID_OPERATION;
-}
-
-status_t AudioPolicyService::startAudioSource(const struct audio_port_config *source,
- const audio_attributes_t *attributes,
- audio_patch_handle_t *handle)
-{
- return INVALID_OPERATION;
-}
-
-status_t AudioPolicyService::stopAudioSource(audio_patch_handle_t handle)
-{
- return INVALID_OPERATION;
-}
-
-status_t AudioPolicyService::setMasterMono(bool mono)
-{
- return INVALID_OPERATION;
-}
-
-status_t AudioPolicyService::getMasterMono(bool *mono)
-{
- return INVALID_OPERATION;
-}
-
-}; // namespace android
diff --git a/services/audiopolicy/service/AudioPolicyService.cpp b/services/audiopolicy/service/AudioPolicyService.cpp
index b6b6116..c4f6367 100644
--- a/services/audiopolicy/service/AudioPolicyService.cpp
+++ b/services/audiopolicy/service/AudioPolicyService.cpp
@@ -39,11 +39,6 @@
#include <system/audio.h>
#include <system/audio_policy.h>
-#ifdef USE_LEGACY_AUDIO_POLICY
-#include <hardware/hardware.h>
-#include <hardware/audio_policy.h>
-#endif
-
namespace android {
static const char kDeadlockedString[] = "AudioPolicyService may be deadlocked\n";
@@ -54,11 +49,6 @@
static const nsecs_t kAudioCommandTimeoutNs = seconds(3); // 3 seconds
-#ifdef USE_LEGACY_AUDIO_POLICY
-namespace {
- extern struct audio_policy_service_ops aps_ops;
-};
-#endif
// ----------------------------------------------------------------------------
@@ -80,40 +70,8 @@
// start output activity command thread
mOutputCommandThread = new AudioCommandThread(String8("ApmOutput"), this);
-#ifdef USE_LEGACY_AUDIO_POLICY
- ALOGI("AudioPolicyService CSTOR in legacy mode");
-
- /* instantiate the audio policy manager */
- const struct hw_module_t *module;
- int rc = hw_get_module(AUDIO_POLICY_HARDWARE_MODULE_ID, &module);
- if (rc) {
- return;
- }
- rc = audio_policy_dev_open(module, &mpAudioPolicyDev);
- ALOGE_IF(rc, "couldn't open audio policy device (%s)", strerror(-rc));
- if (rc) {
- return;
- }
-
- rc = mpAudioPolicyDev->create_audio_policy(mpAudioPolicyDev, &aps_ops, this,
- &mpAudioPolicy);
- ALOGE_IF(rc, "couldn't create audio policy (%s)", strerror(-rc));
- if (rc) {
- return;
- }
-
- rc = mpAudioPolicy->init_check(mpAudioPolicy);
- ALOGE_IF(rc, "couldn't init_check the audio policy (%s)", strerror(-rc));
- if (rc) {
- return;
- }
- ALOGI("Loaded audio policy from %s (%s)", module->name, module->id);
-#else
- ALOGI("AudioPolicyService CSTOR in new mode");
-
mAudioPolicyClient = new AudioPolicyClient(this);
mAudioPolicyManager = createAudioPolicyManager(mAudioPolicyClient);
-#endif
}
// load audio processing modules
sp<AudioPolicyEffects>audioPolicyEffects = new AudioPolicyEffects();
@@ -129,17 +87,8 @@
mAudioCommandThread->exit();
mOutputCommandThread->exit();
-#ifdef USE_LEGACY_AUDIO_POLICY
- if (mpAudioPolicy != NULL && mpAudioPolicyDev != NULL) {
- mpAudioPolicyDev->destroy_audio_policy(mpAudioPolicyDev, mpAudioPolicy);
- }
- if (mpAudioPolicyDev != NULL) {
- audio_policy_dev_close(mpAudioPolicyDev);
- }
-#else
destroyAudioPolicyManager(mAudioPolicyManager);
delete mAudioPolicyClient;
-#endif
mNotificationClients.clear();
mAudioPolicyEffects.clear();
@@ -187,14 +136,12 @@
Mutex::Autolock _l(mNotificationClientsLock);
mNotificationClients.removeItem(uid);
}
-#ifndef USE_LEGACY_AUDIO_POLICY
{
Mutex::Autolock _l(mLock);
if (mAudioPolicyManager) {
mAudioPolicyManager->releaseResourcesForUid(uid);
}
}
-#endif
}
void AudioPolicyService::onAudioPortListUpdate()
@@ -360,11 +307,7 @@
char buffer[SIZE];
String8 result;
-#ifdef USE_LEGACY_AUDIO_POLICY
- snprintf(buffer, SIZE, "PolicyManager Interface: %p\n", mpAudioPolicy);
-#else
snprintf(buffer, SIZE, "AudioPolicyManager: %p\n", mAudioPolicyManager);
-#endif
result.append(buffer);
snprintf(buffer, SIZE, "Command Thread: %p\n", mAudioCommandThread.get());
result.append(buffer);
@@ -394,15 +337,9 @@
mTonePlaybackThread->dump(fd);
}
-#ifdef USE_LEGACY_AUDIO_POLICY
- if (mpAudioPolicy) {
- mpAudioPolicy->dump(mpAudioPolicy, fd);
- }
-#else
if (mAudioPolicyManager) {
mAudioPolicyManager->dump(fd);
}
-#endif
if (locked) mLock.unlock();
}
@@ -1210,29 +1147,4 @@
int aps_set_voice_volume(void *service, float volume, int delay_ms);
};
-#ifdef USE_LEGACY_AUDIO_POLICY
-namespace {
- struct audio_policy_service_ops aps_ops = {
- .open_output = aps_open_output,
- .open_duplicate_output = aps_open_dup_output,
- .close_output = aps_close_output,
- .suspend_output = aps_suspend_output,
- .restore_output = aps_restore_output,
- .open_input = aps_open_input,
- .close_input = aps_close_input,
- .set_stream_volume = aps_set_stream_volume,
- .invalidate_stream = aps_invalidate_stream,
- .set_parameters = aps_set_parameters,
- .get_parameters = aps_get_parameters,
- .start_tone = aps_start_tone,
- .stop_tone = aps_stop_tone,
- .set_voice_volume = aps_set_voice_volume,
- .move_effects = aps_move_effects,
- .load_hw_module = aps_load_hw_module,
- .open_output_on_module = aps_open_output_on_module,
- .open_input_on_module = aps_open_input_on_module,
- };
-}; // namespace <unnamed>
-#endif
-
}; // namespace android
diff --git a/services/audiopolicy/service/AudioPolicyService.h b/services/audiopolicy/service/AudioPolicyService.h
index a310735..8eb4f2d 100644
--- a/services/audiopolicy/service/AudioPolicyService.h
+++ b/services/audiopolicy/service/AudioPolicyService.h
@@ -30,10 +30,6 @@
#include <media/ToneGenerator.h>
#include <media/AudioEffect.h>
#include <media/AudioPolicy.h>
-#ifdef USE_LEGACY_AUDIO_POLICY
-#include <hardware/audio_policy.h>
-#include <hardware_legacy/AudioPolicyInterface.h>
-#endif
#include "AudioPolicyEffects.h"
#include "managerdefault/AudioPolicyManager.h"
diff --git a/services/camera/libcameraservice/CameraService.cpp b/services/camera/libcameraservice/CameraService.cpp
index dd9029e..85faac6 100644
--- a/services/camera/libcameraservice/CameraService.cpp
+++ b/services/camera/libcameraservice/CameraService.cpp
@@ -470,8 +470,8 @@
// CameraInfo is for android.hardware.Camera which does not
// support external camera facing. The closest approximation would be
// front camera.
- if (cameraInfo->orientation == CAMERA_FACING_EXTERNAL) {
- cameraInfo->orientation = CAMERA_FACING_FRONT;
+ if (cameraInfo->facing == CAMERA_FACING_EXTERNAL) {
+ cameraInfo->facing = CAMERA_FACING_FRONT;
}
}
return rc;
@@ -2556,7 +2556,8 @@
write(fd, result.string(), result.size());
} else {
result.appendFormat(" Facing: %s\n",
- info.facing == CAMERA_FACING_BACK ? "BACK" : "FRONT");
+ info.facing == CAMERA_FACING_BACK ? "BACK" :
+ info.facing == CAMERA_FACING_FRONT ? "FRONT" : "EXTERNAL");
result.appendFormat(" Orientation: %d\n", info.orientation);
int deviceVersion;
if (mModule->getModuleApiVersion() < CAMERA_MODULE_API_VERSION_2_0) {