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 AVDEMUXER_DEMO_H
17 #define AVDEMUXER_DEMO_H
18 
19 #include <memory>
20 #include <vector>
21 #include <map>
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 #include "libavformat/avformat.h"
27 #include "libavcodec/avcodec.h"
28 #include "libavutil/dict.h"
29 #ifdef __cplusplus
30 }
31 #endif
32 
33 #include "native_avcodec_base.h"
34 #include "native_avformat.h"
35 #include "native_avdemuxer.h"
36 
37 namespace OHOS {
38 namespace MediaAVCodec {
39 class AVDemuxerDemo {
40 public:
41     AVDemuxerDemo();
42     ~AVDemuxerDemo();
43     int32_t CreateWithSource(OH_AVSource *avsource);
44     int32_t Destroy();
45     int32_t ReadAllSamples(OH_AVMemory *sample, int32_t tracks);
46     int32_t SelectTrackByID(uint32_t trackIndex);
47     int32_t UnselectTrackByID(uint32_t trackIndex);
48     int32_t PrintInfo(int32_t tracks);
49     bool isEOS(std::map<uint32_t, bool>& countFlag);
50     int32_t ReadSample(uint32_t trackIndex, OH_AVMemory *sample, OH_AVCodecBufferAttr *bufferAttr);
51     int32_t SeekToTime(int64_t millisecond, OH_AVSeekMode mode);
52     // for drm test
53     int32_t SetDrmAppCallback();
54     void GetMediaKeySystemInfo();
55 
56     OH_AVCodecBufferAttr bufferInfo;
57     std::map<int32_t, int64_t> frames_;
58     std::map<int32_t, int64_t> key_frames_;
59 private:
60     OH_AVSource* avsource_ = nullptr;
61     OH_AVDemuxer* avdemxuer_ = nullptr;
62 };
63 }  // namespace MediaAVCodec
64 }  // namespace OHOS
65 #endif