• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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 AVCODEC_BITSTREAM_DUMP_H
17 #define AVCODEC_BITSTREAM_DUMP_H
18 
19 #include <string>
20 #include <thread>
21 #include <mutex>
22 #include <condition_variable>
23 
24 namespace OHOS {
25 namespace MediaAVCodec {
26 enum class BitStreamDumpType {
27     BIT_STREAM_DUMP_TYPE_DEFAULT,
28     BIT_STREAM_DUMP_TYPE_VCODEC,
29     BIT_STREAM_DUMP_TYPE_ACODEC,
30     BIT_STREAM_DUMP_TYPE_MUXER,
31     BIT_STREAM_DUMP_TYPE_DEMUXER,
32     BIT_STREAM_DUMP_TYPE_SOURCE
33 };
34 
35 class __attribute__((visibility("default"))) AVCodecBitStreamDumper {
36 public:
37     static AVCodecBitStreamDumper &GetInstance();
38     void SaveBitStream(BitStreamDumpType type, const std::string &name,
39         const uint32_t index, const uint8_t* buffer, const uint32_t size);
40     bool SwitchEnable();
41 
42 private:
43     AVCodecBitStreamDumper();
44     ~AVCodecBitStreamDumper();
45     int32_t fileCount_ = 0;
46     int32_t bitStreamCount_ = 0;
47     std::unique_ptr<std::thread> thread_;
48     void TaskProcessor();
49     std::mutex mutex_;
50     std::condition_variable cond_;
51     std::string bitstreamString_;
52     bool isDump_ = false;
53     bool isExit_ = false;
54     bool isEnable_ = false;
55     bool isNewFile_ = true;
56 };
57 
58 // AVCodec bitstream dump macro interface
59 #ifdef  BITSTREAM_DUMP_ENABLE
60 #define AVCODEC_BITSTREAM_DUMP(type, name, index, buffer, size)                     \
61     do {                                                                            \
62         (void)OHOS::MediaAVCodec::AVCodecBitStreamDumper::GetInstance().SaveBitStream(     \
63             type, name, index, buffer, size);                                       \
64     } while (0)
65 #else
66 #define AVCODEC_BITSTREAM_DUMP(type, name, index, buffer, size)
67 #endif
68 } // namespace MediaAVCodec
69 } // namespace OHOS
70 
71 #endif // AVCODEC_LOG_DUMP_H