Scanner C++ API
software_video_decoder.h
1 /* Copyright 2016 Carnegie Mellon University
2  *
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 #pragma once
17 
18 #include "scanner/api/kernel.h"
19 #include "scanner/util/queue.h"
20 #include "scanner/video/video_decoder.h"
21 
22 extern "C" {
23 #include "libavcodec/avcodec.h"
24 #include "libavfilter/avfilter.h"
25 #include "libavformat/avformat.h"
26 #include "libavformat/avio.h"
27 #include "libavutil/error.h"
28 #include "libavutil/opt.h"
29 #include "libavutil/pixdesc.h"
30 #include "libswscale/swscale.h"
31 }
32 
33 #include <deque>
34 #include <mutex>
35 #include <vector>
36 
37 namespace scanner {
38 namespace internal {
39 
43  public:
44  SoftwareVideoDecoder(i32 device_id, DeviceType output_type, i32 thread_count);
45 
47 
48  void configure(const FrameInfo& metadata) override;
49 
50  bool feed(const u8* encoded_buffer, size_t encoded_size,
51  bool discontinuity = false) override;
52 
53  bool discard_frame() override;
54 
55  bool get_frame(u8* decoded_buffer, size_t decoded_size) override;
56 
57  int decoded_frames_buffered() override;
58 
59  void wait_until_frames_copied() override;
60 
61  private:
62  void feed_packet(bool flush);
63 
64  int device_id_;
65  DeviceType output_type_;
66  AVPacket packet_;
67  AVCodec* codec_;
68  AVCodecContext* cc_;
69 
70  FrameInfo metadata_;
71  i32 frame_width_;
72  i32 frame_height_;
73  std::vector<u8> conversion_buffer_;
74  bool reset_context_;
75  SwsContext* sws_context_;
76 
77  Queue<AVFrame*> frame_pool_;
78  Queue<AVFrame*> decoded_frame_queue_;
79 };
80 }
81 }
SoftwareVideoDecoder.
Definition: software_video_decoder.h:42
VideoDecoder.
Definition: video_decoder.h:38
Definition: database.cpp:36
SoftwareVideoDecoder(i32 device_id, DeviceType output_type, i32 thread_count)
SoftwareVideoDecoder.
Definition: software_video_decoder.cpp:38
FrameInfo.
Definition: frame.h:34