• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef SINK_BYTEBUFFER_IMPL_H
17 #define SINK_BYTEBUFFER_IMPL_H
18 
19 #include "sink_base.h"
20 #include <mutex>
21 #include <vector>
22 #include "avsharedmemory.h"
23 #include "gst_shared_mem_sink.h"
24 #include "nocopyable.h"
25 
26 namespace OHOS {
27 namespace Media {
28 class SinkBytebufferImpl : public SinkBase, public NoCopyable {
29 public:
30     SinkBytebufferImpl();
31     ~SinkBytebufferImpl() override;
32 
33     int32_t Init() override;
34     int32_t Configure(std::shared_ptr<ProcessorConfig> config) override;
35     int32_t Flush() override;
36     std::shared_ptr<AVSharedMemory> GetOutputBuffer(uint32_t index) override;
37     int32_t ReleaseOutputBuffer(uint32_t index, bool render = false) override;
38     int32_t SetCallback(const std::weak_ptr<IAVCodecEngineObs> &obs) override;
39     bool IsEos() override;
40 
41 private:
42     static void EosCb(GstMemSink *memSink, gpointer userData);
43     static GstFlowReturn NewSampleCb(GstMemSink *memSink, GstBuffer *sample, gpointer userData);
44 
45     int32_t HandleNewSampleCb(GstBuffer *buffer);
46     int32_t FindBufferIndex(uint32_t &index, std::shared_ptr<AVSharedMemory> mem);
47     int32_t AddAdtsHead(std::shared_ptr<AVSharedMemory> mem, uint32_t rawFrameSize);
48 
49     std::mutex mutex_;
50     std::vector<std::shared_ptr<BufferWrapper>> bufferList_;
51     std::weak_ptr<IAVCodecEngineObs> obs_;
52     bool isFirstFrame_ = true;
53     Format bufferFormat_;
54     bool isEos_ = false;
55     bool needAdtsTransform_ = false;
56     AdtsFixedHeader adtsHead_;
57 };
58 } // namespace Media
59 } // namespace OHOS
60 #endif // SINK_BYTEBUFFER_IMPL_H