Skip to content

Commit

Permalink
Merge AP3A.240417.001
Browse files Browse the repository at this point in the history
Change-Id: I8cd6510e585a69a90fe17f1c488b1b0ccf8dbb83
  • Loading branch information
mhl-goog committed Apr 19, 2024
2 parents f990590 + ec02aee commit fde9a56
Show file tree
Hide file tree
Showing 46 changed files with 524 additions and 347 deletions.
21 changes: 21 additions & 0 deletions camera/CameraSessionStats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,16 @@ status_t CameraSessionStats::readFromParcel(const android::Parcel* parcel) {
return err;
}

auto mostRequestedFpsRange = std::make_pair(0,0);
if ((err = parcel->readInt32(&mostRequestedFpsRange.first)) != OK) {
ALOGE("%s: Failed to read frame rate range min info!", __FUNCTION__);
return err;
}
if ((err = parcel->readInt32(&mostRequestedFpsRange.second)) != OK) {
ALOGE("%s: Failed to read frame rate range max info!", __FUNCTION__);
return err;
}

mCameraId = toStdString(id);
mFacing = facing;
mNewCameraState = newCameraState;
Expand All @@ -460,6 +470,7 @@ status_t CameraSessionStats::readFromParcel(const android::Parcel* parcel) {
mUsedZoomOverride = usedZoomOverride;
mSessionIndex = sessionIdx;
mCameraExtensionSessionStats = extStats;
mMostRequestedFpsRange = mostRequestedFpsRange;

return OK;
}
Expand Down Expand Up @@ -577,6 +588,16 @@ status_t CameraSessionStats::writeToParcel(android::Parcel* parcel) const {
return err;
}

if ((err = parcel->writeInt32(mMostRequestedFpsRange.first)) != OK) {
ALOGE("%s: Failed to write frame rate range min info!", __FUNCTION__);
return err;
}

if ((err = parcel->writeInt32(mMostRequestedFpsRange.second)) != OK) {
ALOGE("%s: Failed to write frame rate range max info!", __FUNCTION__);
return err;
}

return OK;
}

Expand Down
7 changes: 7 additions & 0 deletions camera/camera_platform.aconfig
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,10 @@ flag {
purpose: PURPOSE_BUGFIX
}
}

flag {
namespace: "camera_platform"
name: "analytics_24q3"
description: "Miscellaneous camera platform metrics for 24Q3"
bug: "332557570"
}
2 changes: 2 additions & 0 deletions camera/include/camera/CameraSessionStats.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ class CameraSessionStats : public android::Parcelable {

CameraExtensionSessionStats mCameraExtensionSessionStats;

std::pair<int32_t, int32_t> mMostRequestedFpsRange;

// Constructors
CameraSessionStats();
CameraSessionStats(const std::string& cameraId, int facing, int newCameraState,
Expand Down
28 changes: 24 additions & 4 deletions media/codec2/components/flac/C2SoftFlacEnc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <audio_utils/primitives.h>
#include <media/stagefright/foundation/MediaDefs.h>

#include <C2Debug.h>
#include <C2PlatformSupport.h>
#include <SimpleC2Interface.h>

Expand Down Expand Up @@ -81,10 +82,6 @@ class C2SoftFlacEnc::IntfImpl : public SimpleInterface<void>::BaseParams {
FLAC_COMPRESSION_LEVEL_MIN, FLAC_COMPRESSION_LEVEL_MAX)})
.withSetter(Setter<decltype(*mComplexity)>::NonStrictValueWithNoDeps)
.build());
addParameter(
DefineParam(mInputMaxBufSize, C2_PARAMKEY_INPUT_MAX_BUFFER_SIZE)
.withConstValue(new C2StreamMaxBufferSizeInfo::input(0u, 4608))
.build());

addParameter(
DefineParam(mPcmEncodingInfo, C2_PARAMKEY_PCM_ENCODING)
Expand All @@ -96,6 +93,26 @@ class C2SoftFlacEnc::IntfImpl : public SimpleInterface<void>::BaseParams {
})
.withSetter((Setter<decltype(*mPcmEncodingInfo)>::StrictValueWithNoDeps))
.build());

addParameter(
DefineParam(mInputMaxBufSize, C2_PARAMKEY_INPUT_MAX_BUFFER_SIZE)
.withDefault(new C2StreamMaxBufferSizeInfo::input(0u, kMaxBlockSize))
.withFields({
C2F(mInputMaxBufSize, value).any(),
})
.withSetter(MaxInputSizeSetter, mChannelCount, mPcmEncodingInfo)
.build());
}

static C2R MaxInputSizeSetter(bool mayBlock,
C2P<C2StreamMaxBufferSizeInfo::input> &me,
const C2P<C2StreamChannelCountInfo::input> &channelCount,
const C2P<C2StreamPcmEncodingInfo::input> &pcmEncoding) {
(void)mayBlock;
C2R res = C2R::Ok();
int bytesPerSample = pcmEncoding.v.value == C2Config::PCM_FLOAT ? 4 : 2;
me.set().value = kMaxBlockSize * bytesPerSample * channelCount.v.value;
return res;
}

uint32_t getSampleRate() const { return mSampleRate->value; }
Expand Down Expand Up @@ -446,6 +463,9 @@ status_t C2SoftFlacEnc::configureEncoder() {

mBlockSize = FLAC__stream_encoder_get_blocksize(mFlacStreamEncoder);

// Update kMaxBlockSize to match maximum size used by the encoder
CHECK(mBlockSize <= kMaxBlockSize);

ALOGV("encoder successfully configured");
return OK;
}
Expand Down
3 changes: 2 additions & 1 deletion media/codec2/components/flac/C2SoftFlacEnc.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ class C2SoftFlacEnc : public SimpleC2Component {

std::shared_ptr<IntfImpl> mIntf;
const unsigned int kInBlockSize = 1152;
const unsigned int kMaxNumChannels = 2;
static constexpr unsigned int kMaxNumChannels = 2;
static constexpr unsigned int kMaxBlockSize = 4608;
FLAC__StreamEncoder* mFlacStreamEncoder;
FLAC__int32* mInputBufferPcm32;
std::shared_ptr<C2LinearBlock> mOutputBlock;
Expand Down
12 changes: 7 additions & 5 deletions media/codec2/components/mpeg4_h263/C2SoftMpeg4Dec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -469,11 +469,12 @@ void C2SoftMpeg4Dec::process(
mInitialized = false;
}

bool codecConfig = (work->input.flags & C2FrameData::FLAG_CODEC_CONFIG) != 0;

if (!mInitialized) {
uint8_t *vol_data[1]{};
int32_t vol_size = 0;

bool codecConfig = (work->input.flags & C2FrameData::FLAG_CODEC_CONFIG) != 0;
if (codecConfig || volHeader) {
vol_data[0] = bitstream;
vol_size = inSize;
Expand Down Expand Up @@ -512,10 +513,11 @@ void C2SoftMpeg4Dec::process(
return;
}
}
if (codecConfig) {
fillEmptyWork(work);
return;
}
}

if (codecConfig) {
fillEmptyWork(work);
return;
}

size_t inPos = 0;
Expand Down
15 changes: 8 additions & 7 deletions media/codec2/components/opus/C2SoftOpusEnc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ extern "C" {
#include <opus_multistream.h>
}

#define DEFAULT_FRAME_DURATION_MS 20
namespace android {

namespace {
Expand All @@ -38,7 +37,6 @@ constexpr char COMPONENT_NAME[] = "c2.android.opus.encoder";

} // namespace

static const int kMaxNumChannelsSupported = 2;

class C2SoftOpusEnc::IntfImpl : public SimpleInterface<void>::BaseParams {
public:
Expand Down Expand Up @@ -248,10 +246,11 @@ c2_status_t C2SoftOpusEnc::initEncoder() {
mAnchorTimeStamp = 0;
mProcessedSamples = 0;
mFilledLen = 0;
mFrameDurationMs = DEFAULT_FRAME_DURATION_MS;
mFrameDurationMs = kDefaultFrameDurationMs;
if (!mInputBufferPcm16) {
size_t frameSize = (mFrameDurationMs * kMaxSampleRateSupported) / 1000;
mInputBufferPcm16 =
(int16_t*)malloc(kFrameSize * kMaxNumChannels * sizeof(int16_t));
(int16_t*)malloc(frameSize * kMaxNumChannelsSupported * sizeof(int16_t));
}
if (!mInputBufferPcm16) return C2_NO_MEMORY;

Expand Down Expand Up @@ -368,7 +367,9 @@ void C2SoftOpusEnc::process(const std::unique_ptr<C2Work>& work,
}

C2MemoryUsage usage = {C2MemoryUsage::CPU_READ, C2MemoryUsage::CPU_WRITE};
err = pool->fetchLinearBlock(kMaxPayload, usage, &mOutputBlock);
int outCapacity =
kMaxPayload * ((inSize + mNumPcmBytesPerInputFrame) / mNumPcmBytesPerInputFrame);
err = pool->fetchLinearBlock(outCapacity, usage, &mOutputBlock);
if (err != C2_OK) {
ALOGE("fetchLinearBlock for Output failed with status %d", err);
work->result = C2_NO_MEMORY;
Expand Down Expand Up @@ -497,11 +498,11 @@ void C2SoftOpusEnc::process(const std::unique_ptr<C2Work>& work,
uint8_t* outPtr = wView.data() + mBytesEncoded;
int encodedBytes =
opus_multistream_encode(mEncoder, mInputBufferPcm16,
mNumSamplesPerFrame, outPtr, kMaxPayload - mBytesEncoded);
mNumSamplesPerFrame, outPtr, outCapacity - mBytesEncoded);
ALOGV("encoded %i Opus bytes from %zu PCM bytes", encodedBytes,
processSize);

if (encodedBytes < 0 || encodedBytes > (kMaxPayload - mBytesEncoded)) {
if (encodedBytes < 0 || encodedBytes > (outCapacity - mBytesEncoded)) {
ALOGE("opus_encode failed, encodedBytes : %d", encodedBytes);
mSignalledError = true;
work->result = C2_CORRUPTED;
Expand Down
13 changes: 7 additions & 6 deletions media/codec2/components/opus/C2SoftOpusEnc.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,13 @@ struct C2SoftOpusEnc : public SimpleC2Component {
uint32_t drainMode,
const std::shared_ptr<C2BlockPool> &pool) override;
private:
/* OPUS_FRAMESIZE_20_MS */
const int kFrameSize = 960;
const int kMaxSampleRate = 48000;
const int kMinSampleRate = 8000;
const int kMaxPayload = (4000 * kMaxSampleRate) / kMinSampleRate;
const int kMaxNumChannels = 8;
static const int kMaxNumChannelsSupported = 2;
static const int kMaxSampleRateSupported = 48000;
static const int kDefaultFrameDurationMs = 20;
// For a frame duration of 20ms, payload recommended size is 1276 as per
// https://www.opus-codec.org/docs/html_api/group__opusencoder.html.
// For 40ms, 60ms, .. payload size will change proportionately, 1276 x 2, 1276 x 3, ..
static const int kMaxPayload = 1500; // from tests/test_opus_encode.c

std::shared_ptr<IntfImpl> mIntf;
std::shared_ptr<C2LinearBlock> mOutputBlock;
Expand Down
8 changes: 7 additions & 1 deletion media/codec2/hal/client/GraphicsTracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,8 @@ void GraphicsTracker::commitAllocate(c2_status_t res, const std::shared_ptr<Buff
auto mapRet = mDequeued.emplace(bid, *pBuffer);
CHECK(mapRet.second);
} else {
ALOGD("allocate error(%d): Dequeued(%zu), Dequeuable(%d)",
(int)res, mDequeued.size(), mDequeueable + 1);
if (adjustDequeueConfLocked(updateDequeue)) {
return;
}
Expand Down Expand Up @@ -629,7 +631,11 @@ c2_status_t GraphicsTracker::_allocate(const std::shared_ptr<BufferCache> &cache
::android::status_t status = igbp->dequeueBuffer(
&slotId, &fence, width, height, format, usage, &outBufferAge, &outTimestamps);
if (status < ::android::OK) {
ALOGE("dequeueBuffer() error %d", (int)status);
if (status == ::android::TIMED_OUT || status == ::android::WOULD_BLOCK) {
ALOGW("BQ might not be ready for dequeueBuffer()");
return C2_BLOCKING;
}
ALOGE("BQ in inconsistent status. dequeueBuffer() error %d", (int)status);
return C2_CORRUPTED;
}
cache->waitOnSlot(slotId);
Expand Down
10 changes: 7 additions & 3 deletions media/codec2/sfplugin/CCodecBuffers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1594,19 +1594,23 @@ void LinearOutputBuffers::flush(

sp<Codec2Buffer> LinearOutputBuffers::wrap(const std::shared_ptr<C2Buffer> &buffer) {
if (buffer == nullptr) {
ALOGV("[%s] using a dummy buffer", mName);
ALOGD("[%s] received null buffer", mName);
return new LocalLinearBuffer(mFormat, new ABuffer(0));
}
if (buffer->data().type() != C2BufferData::LINEAR) {
ALOGV("[%s] non-linear buffer %d", mName, buffer->data().type());
ALOGW("[%s] non-linear buffer %d", mName, buffer->data().type());
// We expect linear output buffers from the component.
return nullptr;
}
if (buffer->data().linearBlocks().size() != 1u) {
ALOGV("[%s] no linear buffers", mName);
ALOGW("[%s] no linear buffers", mName);
// We expect one and only one linear block from the component.
return nullptr;
}
if (buffer->data().linearBlocks().front().size() == 0) {
ALOGD("[%s] received 0-sized buffer", mName);
return new LocalLinearBuffer(mFormat, new ABuffer(0));
}
sp<Codec2Buffer> clientBuffer = ConstLinearBlockBuffer::Allocate(mFormat, buffer);
if (clientBuffer == nullptr) {
ALOGD("[%s] ConstLinearBlockBuffer::Allocate failed", mName);
Expand Down
7 changes: 7 additions & 0 deletions media/codec2/sfplugin/Codec2Buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,17 @@ sp<ConstLinearBlockBuffer> ConstLinearBlockBuffer::Allocate(
if (!buffer
|| buffer->data().type() != C2BufferData::LINEAR
|| buffer->data().linearBlocks().size() != 1u) {
if (!buffer) {
ALOGD("ConstLinearBlockBuffer::Allocate: null buffer");
} else {
ALOGW("ConstLinearBlockBuffer::Allocate: type=%d # linear blocks=%zu",
buffer->data().type(), buffer->data().linearBlocks().size());
}
return nullptr;
}
C2ReadView readView(buffer->data().linearBlocks()[0].map().get());
if (readView.error() != C2_OK) {
ALOGW("ConstLinearBlockBuffer::Allocate: readView.error()=%d", readView.error());
return nullptr;
}
return new ConstLinearBlockBuffer(format, std::move(readView), buffer);
Expand Down
43 changes: 8 additions & 35 deletions media/libaudioclient/AudioTrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,26 +236,10 @@ status_t AudioTrack::getMetrics(mediametrics::Item * &item)
return NO_ERROR;
}

AudioTrack::AudioTrack() : AudioTrack(AttributionSourceState())
{
}

AudioTrack::AudioTrack(const AttributionSourceState& attributionSource)
: mStatus(NO_INIT),
mState(STATE_STOPPED),
mPreviousPriority(ANDROID_PRIORITY_NORMAL),
mPreviousSchedulingGroup(SP_DEFAULT),
mPausedPosition(0),
mSelectedDeviceId(AUDIO_PORT_HANDLE_NONE),
mRoutedDeviceId(AUDIO_PORT_HANDLE_NONE),
mPauseTimeRealUs(0),
mClientAttributionSource(attributionSource),
mAudioTrackCallback(new AudioTrackCallback())
: mClientAttributionSource(attributionSource),
mPauseTimeRealUs(0)
{
mAttributes.content_type = AUDIO_CONTENT_TYPE_UNKNOWN;
mAttributes.usage = AUDIO_USAGE_UNKNOWN;
mAttributes.flags = AUDIO_FLAG_NONE;
strcpy(mAttributes.tags, "");
}

AudioTrack::AudioTrack(
Expand All @@ -275,21 +259,12 @@ AudioTrack::AudioTrack(
bool doNotReconnect,
float maxRequiredSpeed,
audio_port_handle_t selectedDeviceId)
: mStatus(NO_INIT),
mState(STATE_STOPPED),
mPreviousPriority(ANDROID_PRIORITY_NORMAL),
mPreviousSchedulingGroup(SP_DEFAULT),
mPausedPosition(0),
mAudioTrackCallback(new AudioTrackCallback())
{
mAttributes = AUDIO_ATTRIBUTES_INITIALIZER;

// make_unique does not aggregate init until c++20
mSetParams = std::unique_ptr<SetParams>{
new SetParams{streamType, sampleRate, format, channelMask, frameCount, flags, callback,
notificationFrames, 0 /*sharedBuffer*/, false /*threadCanCallJava*/,
sessionId, transferType, offloadInfo, attributionSource, pAttributes,
doNotReconnect, maxRequiredSpeed, selectedDeviceId}};
mSetParams = std::make_unique<SetParams>(
streamType, sampleRate, format, channelMask, frameCount, flags, callback,
notificationFrames, nullptr /*sharedBuffer*/, false /*threadCanCallJava*/,
sessionId, transferType, offloadInfo, attributionSource, pAttributes,
doNotReconnect, maxRequiredSpeed, selectedDeviceId);
}

namespace {
Expand Down Expand Up @@ -462,9 +437,6 @@ void AudioTrack::createDummyAudioSessionForBluetooth() {
ALOGD("split_a2dp dummy track stop completed");
}
void AudioTrack::stopAndJoinCallbacks() {
// Prevent nullptr crash if it did not open properly.
if (mStatus != NO_ERROR) return;

// Make sure that callback function exits in the case where
// it is looping on buffer full condition in obtainBuffer().
// Otherwise the callback thread will never exit.
Expand Down Expand Up @@ -986,6 +958,7 @@ void AudioTrack::stop()
const int64_t beginNs = systemTime();

AutoMutex lock(mLock);
if (mProxy == nullptr) return; // not successfully initialized.
mediametrics::Defer defer([&]() {
mediametrics::LogItem(mMetricsId)
.set(AMEDIAMETRICS_PROP_EVENT, AMEDIAMETRICS_PROP_EVENT_VALUE_STOP)
Expand Down
Loading

0 comments on commit fde9a56

Please sign in to comment.