blob: a9b4d18651b267dedcd2eb94dda5a1205a3decb0 [file] [log] [blame]
Glenn Kasten01066232012-02-27 11:50:44 -08001/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#define LOG_TAG "MonoPipeReader"
18//#define LOG_NDEBUG 0
19
20#include <cutils/compiler.h>
21#include <utils/Log.h>
Glenn Kasten2dd4bdd2012-08-29 11:10:32 -070022#include <media/nbaio/MonoPipeReader.h>
Glenn Kasten01066232012-02-27 11:50:44 -080023
24namespace android {
25
26MonoPipeReader::MonoPipeReader(MonoPipe* pipe) :
27 NBAIO_Source(pipe->mFormat),
Glenn Kastened99c2b2016-12-12 08:31:24 -080028 mPipe(pipe), mFifoReader(mPipe->mFifo, true /*throttlesWriter*/)
Glenn Kasten01066232012-02-27 11:50:44 -080029{
30}
31
32MonoPipeReader::~MonoPipeReader()
33{
34}
35
36ssize_t MonoPipeReader::availableToRead()
37{
38 if (CC_UNLIKELY(!mNegotiated)) {
39 return NEGOTIATE;
40 }
Glenn Kastened99c2b2016-12-12 08:31:24 -080041 ssize_t ret = mFifoReader.available();
42 ALOG_ASSERT(ret <= mPipe->mMaxFrames);
Glenn Kasten01066232012-02-27 11:50:44 -080043 return ret;
44}
45
Glenn Kastend79072e2016-01-06 08:41:20 -080046ssize_t MonoPipeReader::read(void *buffer, size_t count)
Glenn Kasten01066232012-02-27 11:50:44 -080047{
48 // count == 0 is unlikely and not worth checking for explicitly; will be handled automatically
Glenn Kastened99c2b2016-12-12 08:31:24 -080049 ssize_t actual = mFifoReader.read(buffer, count);
50 ALOG_ASSERT(actual <= count);
51 if (CC_UNLIKELY(actual <= 0)) {
52 return actual;
Glenn Kasten01066232012-02-27 11:50:44 -080053 }
Glenn Kastened99c2b2016-12-12 08:31:24 -080054 mFramesRead += (size_t) actual;
55 return actual;
Glenn Kasten01066232012-02-27 11:50:44 -080056}
57
Andy Hung818e7a32016-02-16 18:08:07 -080058void MonoPipeReader::onTimestamp(const ExtendedTimestamp &timestamp)
Glenn Kasten894d6be2013-08-26 10:29:28 -070059{
60 mPipe->mTimestampMutator.push(timestamp);
61}
62
Glenn Kasten01066232012-02-27 11:50:44 -080063} // namespace android