Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 99ffda87 authored by The Android Open Source Project's avatar The Android Open Source Project
Browse files

auto import from //depot/cupcake/@137055

parent 925a349b
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -125,7 +125,8 @@ public:
     * channelCount:       Number of PCM channels (e.g 2 for stereo).
     * frameCount:         Total size of track PCM buffer in frames. This defines the
     *                     latency of the track.
     * flags:              Reserved for future use.
     * flags:              A bitmask of acoustic values from enum record_flags.  It enables
     *                     AGC, NS, and IIR.
     * cbf:                Callback function. If not null, this function is called periodically
     *                     to provide new PCM data.
     * notificationFrames: The callback function is called each time notificationFrames PCM
@@ -133,6 +134,12 @@ public:
     * user                Context for use by the callback receiver.
     */

     enum record_flags {
         RECORD_AGC_ENABLE = AudioSystem::AGC_ENABLE,
         RECORD_NS_ENABLE  = AudioSystem::NS_ENABLE,
         RECORD_IIR_ENABLE = AudioSystem::TX_IIR_ENABLE
     };

                        AudioRecord(int streamType,
                                    uint32_t sampleRate = 0,
                                    int format          = 0,
+2 −0
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ namespace android {

class ISurface;
class ICamera;
class IMediaPlayerClient;

class IMediaRecorder: public IInterface
{
@@ -41,6 +42,7 @@ public:
    virtual	status_t		setOutputFile(int fd, int64_t offset, int64_t length) = 0;
    virtual	status_t		setVideoSize(int width, int height) = 0;
    virtual	status_t		setVideoFrameRate(int frames_per_second) = 0;
    virtual     status_t                setListener(const sp<IMediaPlayerClient>& listener) = 0;
    virtual	status_t		prepare() = 0;
    virtual	status_t		getMaxAmplitude(int* max) = 0;
    virtual	status_t		start() = 0;
+2 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@
#define ANDROID_PVMEDIARECORDER_H

#include <media/mediarecorder.h>
#include <media/IMediaPlayerClient.h>

namespace android {

@@ -44,6 +45,7 @@ public:
    status_t setPreviewSurface(const sp<ISurface>& surface);
    status_t setOutputFile(const char *path);
    status_t setOutputFile(int fd, int64_t offset, int64_t length);
    status_t setListener(const sp<IMediaPlayerClient>& listener);
    status_t prepare();
    status_t start();
    status_t stop();
+31 −8
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@
#define ANDROID_MEDIARECORDER_H

#include <utils.h>
#include <media/IMediaPlayerClient.h>

namespace android {

@@ -87,7 +88,24 @@ enum media_recorder_states {
    MEDIA_RECORDER_RECORDING             = 1 << 4,
};

class MediaRecorder
// The "msg" code passed to the listener in notify.
enum {
    MEDIA_RECORDER_EVENT_ERROR                    = 1
};

enum {
    MEDIA_RECORDER_ERROR_UNKNOWN                  = 1
};

// ----------------------------------------------------------------------------
// ref-counted object for callbacks
class MediaRecorderListener: virtual public RefBase
{
public:
    virtual void notify(int msg, int ext1, int ext2) = 0;
};

class MediaRecorder : public BnMediaPlayerClient
{
public:
    MediaRecorder();
@@ -105,6 +123,7 @@ public:
    status_t    setOutputFile(int fd, int64_t offset, int64_t length);
    status_t    setVideoSize(int width, int height);
    status_t    setVideoFrameRate(int frames_per_second);
    status_t    setListener(const sp<MediaRecorderListener>& listener);
    status_t    prepare();
    status_t    getMaxAmplitude(int* max);
    status_t    start();
@@ -113,18 +132,22 @@ public:
    status_t    init();
    status_t    close();
    status_t    release();
    void        notify(int msg, int ext1, int ext2);

private:
    void                    doCleanUp();
    status_t                doReset();

    sp<IMediaRecorder>          mMediaRecorder;
    sp<MediaRecorderListener>   mListener;
    media_recorder_states       mCurrentState;
    bool                        mIsAudioSourceSet;
    bool                        mIsVideoSourceSet;
    bool                        mIsAudioEncoderSet;
    bool                        mIsVideoEncoderSet;
    bool                        mIsOutputFileSet;
    Mutex                       mLock;
    Mutex                       mNotifyLock;
};

};  // namespace android
+22 −3
Original line number Diff line number Diff line
@@ -128,8 +128,23 @@ status_t AudioRecord::set(
        return BAD_VALUE;
    }

    // TODO: Get input frame count from hardware.
    int minFrameCount = 1024*2;
    // validate framecount
    size_t inputBuffSizeInBytes = -1;
    if (AudioSystem::getInputBufferSize(sampleRate, format, channelCount, &inputBuffSizeInBytes)
            != NO_ERROR) {
        LOGE("AudioSystem could not query the input buffer size.");
        return NO_INIT;    
    }
    if (inputBuffSizeInBytes == 0) {
        LOGE("Recording parameters are not supported: sampleRate %d, channelCount %d, format %d",
            sampleRate, channelCount, format);
        return BAD_VALUE;
    }
    int frameSizeInBytes = channelCount * (format == AudioSystem::PCM_16_BIT ? 2 : 1);

    // We use 2* size of input buffer for ping pong use of record buffer.
    int minFrameCount = 2 * inputBuffSizeInBytes / frameSizeInBytes;
    LOGV("AudioRecord::set() minFrameCount = %d", minFrameCount);

    if (frameCount == 0) {
        frameCount = minFrameCount;
@@ -144,7 +159,11 @@ status_t AudioRecord::set(
    // open record channel
    status_t status;
    sp<IAudioRecord> record = audioFlinger->openRecord(getpid(), streamType,
            sampleRate, format, channelCount, frameCount, flags, &status);
                                                       sampleRate, format,
                                                       channelCount,
                                                       frameCount,
                                                       ((uint16_t)flags) << 16, 
                                                       &status);
    if (record == 0) {
        LOGE("AudioFlinger could not create record track, status: %d", status);
        return status;
Loading