MonoPipeReader.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  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. #define LOG_TAG "MonoPipeReader"
  17. //#define LOG_NDEBUG 0
  18. #include <cutils/compiler.h>
  19. #include <utils/Log.h>
  20. #include <media/nbaio/MonoPipeReader.h>
  21. namespace android {
  22. MonoPipeReader::MonoPipeReader(MonoPipe* pipe) :
  23. NBAIO_Source(pipe->mFormat),
  24. mPipe(pipe), mFifoReader(mPipe->mFifo, true /*throttlesWriter*/)
  25. {
  26. }
  27. MonoPipeReader::~MonoPipeReader()
  28. {
  29. }
  30. ssize_t MonoPipeReader::availableToRead()
  31. {
  32. if (CC_UNLIKELY(!mNegotiated)) {
  33. return NEGOTIATE;
  34. }
  35. ssize_t ret = mFifoReader.available();
  36. ALOG_ASSERT(ret <= mPipe->mMaxFrames);
  37. return ret;
  38. }
  39. ssize_t MonoPipeReader::read(void *buffer, size_t count)
  40. {
  41. // count == 0 is unlikely and not worth checking for explicitly; will be handled automatically
  42. ssize_t actual = mFifoReader.read(buffer, count);
  43. ALOG_ASSERT(actual <= count);
  44. if (CC_UNLIKELY(actual <= 0)) {
  45. return actual;
  46. }
  47. mFramesRead += (size_t) actual;
  48. return actual;
  49. }
  50. void MonoPipeReader::onTimestamp(const ExtendedTimestamp &timestamp)
  51. {
  52. mPipe->mTimestampMutator.push(timestamp);
  53. }
  54. } // namespace android