1 /*
2  * Copyright (c) 2023-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 HISTREAMER_PIPELINE_DUMP_BUFFER_H
17 #define HISTREAMER_PIPELINE_DUMP_BUFFER_H
18 
19 #define DEMUXER_INPUT_PEEK "hst_dump_demuxer_input_peek.data"
20 #define DEMUXER_INPUT_GET "hst_dump_demuxer_input_get.data"
21 #define DEMUXER_OUTPUT "hst_dump_demuxer_output.data"
22 #define DECODER_OUTPUT "hst_dump_decoder_output.data"
23 
24 #include <cstddef>
25 #include <cstdint>
26 #include <iosfwd>
27 #include <memory>
28 #include "plugin/plugin_buffer.h"
29 #include "buffer/avbuffer.h"
30 
31 namespace OHOS {
32 namespace Media {
33 // Modify DUMP_BUFFER2FILE_ENABLE to 1 to dump buffer to file.
34 #ifndef DUMP_BUFFER2FILE_ENABLE
35 #define DUMP_BUFFER2FILE_ENABLE 0
36 #endif
37 
38 // Modify DUMP_BUFFER2LOG_ENABLE to 1 to dump buffer first 10 bytes to log.
39 #ifndef DUMP_BUFFER2LOG_ENABLE
40 #define DUMP_BUFFER2LOG_ENABLE 0
41 #endif
42 
43 #if DUMP_BUFFER2FILE_ENABLE
44 #define DUMP_BUFFER2FILE(fileName, buffer) OHOS::Media::Pipeline::DumpBufferToFile(fileName, buffer)
45 #define DUMP_BUFFER2FILE_PREPARE() OHOS::Media::Pipeline::PrepareDumpDir()
46 #define DUMP_BUFFER2FILE_END() OHOS::Media::Pipeline::EndDumpFile()
47 #else
48 #define DUMP_BUFFER2FILE(fileName, buffer)
49 #define DUMP_BUFFER2FILE_PREPARE()
50 #define DUMP_BUFFER2FILE_END()
51 #endif
52 #define DUMP_FILE_DIR "/data/media/pipelinedump/"
53 #define DUMP_BUFFER2LOG_SIZE 10 // Dump first 10 bytes of buffer.
54 #if DUMP_BUFFER2LOG_ENABLE
55 #define DUMP_BUFFER2LOG(desc, buffer, offset) \
56     OHOS::Media::Pipeline::DumpBufferToLog(desc, buffer, offset, DUMP_BUFFER2LOG_SIZE)
57 #else
58 #define DUMP_BUFFER2LOG(desc, buffer, offset)
59 #endif
60 
61 void DumpAVBufferToFile(const std::string& para, const std::string& fileName,
62     const std::shared_ptr<AVBuffer>& buffer);
63 void PrepareDumpDir();
64 void EndDumpFile();
65 void DumpBufferToLog(const char* desc, const std::shared_ptr<Plugins::Buffer>& buffer, uint64_t offset,
66     size_t dumpSize);
67 } // Media
68 } // OHOS
69 #endif // HISTREAMER_PIPELINE_DUMP_BUFFER_H
70