blob: 17ac06d89a6c4635e1d467bc370fc04426f4de84 [file] [log] [blame]
Wonsik Kime1104ca2020-11-24 15:01:33 -08001/*
2 * Copyright 2019 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#ifndef FRAME_REASSEMBLER_H_
18#define FRAME_REASSEMBLER_H_
19
20#include <set>
21#include <memory>
22
23#include <media/MediaCodecBuffer.h>
24
25#include <C2Config.h>
26#include <C2Work.h>
27
28namespace android {
29
30class FrameReassembler {
31public:
32 FrameReassembler();
33
34 void init(
35 const std::shared_ptr<C2BlockPool> &pool,
36 C2MemoryUsage usage,
37 uint32_t frameSize,
38 uint32_t sampleRate,
39 uint32_t channelCount,
40 C2Config::pcm_encoding_t encoding);
41 void updateFrameSize(uint32_t frameSize);
42 void updateSampleRate(uint32_t sampleRate);
43 void updateChannelCount(uint32_t channelCount);
44 void updatePcmEncoding(C2Config::pcm_encoding_t encoding);
45 void reset();
46 void flush();
47
48 explicit operator bool() const;
49
50 c2_status_t process(
51 const sp<MediaCodecBuffer> &buffer,
52 std::list<std::unique_ptr<C2Work>> *items);
53
54private:
55 std::shared_ptr<C2BlockPool> mBlockPool;
56 C2MemoryUsage mUsage;
57 std::optional<uint32_t> mFrameSize;
58 uint32_t mSampleRate;
59 uint32_t mChannelCount;
60 C2Config::pcm_encoding_t mEncoding;
61 std::list<std::unique_ptr<C2Work>> mPendingWork;
62 C2WorkOrdinalStruct mCurrentOrdinal;
63 std::shared_ptr<C2LinearBlock> mCurrentBlock;
64 std::optional<C2WriteView> mWriteView;
65
66 uint64_t bytesToSamples(size_t numBytes) const;
67 size_t usToSamples(uint64_t us) const;
68 uint32_t bytesPerSample() const;
69
70 void finishCurrentBlock(std::list<std::unique_ptr<C2Work>> *items);
71};
72
73} // namespace android
74
75#endif // FRAME_REASSEMBLER_H_