Scanner C++ API
software_video_encoder.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_encoder.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  SoftwareVideoEncoder(i32 device_id, DeviceType output_type, i32 thread_count);
45 
47 
48  void configure(const FrameInfo& metadata, const EncodeOptions& opts) override;
49 
50  bool feed(const u8* frame_buffer, size_t frame_size) override;
51 
52  bool flush() override;
53 
54  bool get_packet(u8* packet_buffer, size_t packet_size,
55  size_t& actual_packet_size) override;
56 
57  int decoded_packets_buffered() override;
58 
59  void wait_until_packets_copied() override;
60 
61  private:
62  void feed_frame(bool flush);
63 
64  int device_id_;
65  DeviceType output_type_;
66  AVCodec* codec_;
67  AVCodecContext* cc_;
68  AVBitStreamFilterContext* annexb_;
69 
70  FrameInfo metadata_;
71  i32 frame_width_;
72  i32 frame_height_;
73  SwsContext* sws_context_;
74  bool was_reset_;
75 
76  i32 frame_id_;
77  AVFrame* frame_;
78  std::deque<AVPacket*> ready_packet_queue_;
79 };
80 }
81 }
Definition: video_encoder.h:34
SoftwareVideoEncoder(i32 device_id, DeviceType output_type, i32 thread_count)
SoftwareVideoEncoder.
Definition: software_video_encoder.cpp:48
Definition: database.cpp:36
VideoEncoder.
Definition: video_encoder.h:42
SoftwareVideoEncoder.
Definition: software_video_encoder.h:42
FrameInfo.
Definition: frame.h:34