]> git.sesse.net Git - nageru/blob - quicksync_encoder.h
Support switching Y'CbCr coefficients midway, which will allow doing the Right Thing...
[nageru] / quicksync_encoder.h
1 // Hardware H.264 encoding via VAAPI. Heavily modified based on example
2 // code by Intel. Intel's original copyright and license is reproduced below:
3 //
4 // Copyright (c) 2007-2013 Intel Corporation. All Rights Reserved.
5 //
6 // Permission is hereby granted, free of charge, to any person obtaining a
7 // copy of this software and associated documentation files (the
8 // "Software"), to deal in the Software without restriction, including
9 // without limitation the rights to use, copy, modify, merge, publish,
10 // distribute, sub license, and/or sell copies of the Software, and to
11 // permit persons to whom the Software is furnished to do so, subject to
12 // the following conditions:
13 // 
14 // The above copyright notice and this permission notice (including the
15 // next paragraph) shall be included in all copies or substantial portions
16 // of the Software.
17 // 
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 // IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
22 // ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
26 #ifndef _H264ENCODE_H
27 #define _H264ENCODE_H
28
29 #include <epoxy/gl.h>
30 #include <movit/image_format.h>
31 #include <stdbool.h>
32 #include <stdint.h>
33 #include <memory>
34 #include <string>
35 #include <vector>
36
37 extern "C" {
38 #include <libavformat/avformat.h>
39 }
40
41 #include "ref_counted_gl_sync.h"
42
43 class DiskSpaceEstimator;
44 class Mux;
45 class QSurface;
46 class QuickSyncEncoderImpl;
47 class RefCountedFrame;
48 class X264Encoder;
49
50 namespace movit {
51 class ResourcePool;
52 }  // namespace movit
53
54 // This is just a pimpl, because including anything X11-related in a .h file
55 // tends to trip up Qt. All the real logic is in QuickSyncEncoderImpl,
56 // defined in quicksync_encoder_impl.h.
57 class QuickSyncEncoder {
58 public:
59         QuickSyncEncoder(const std::string &filename, movit::ResourcePool *resource_pool, QSurface *surface, const std::string &va_display, int width, int height, AVOutputFormat *oformat, X264Encoder *x264_encoder, DiskSpaceEstimator *disk_space_estimator);
60         ~QuickSyncEncoder();
61
62         void set_stream_mux(Mux *mux);  // Does not take ownership. Must be called unless x264 is used for the stream.
63         void add_audio(int64_t pts, std::vector<float> audio);
64         bool begin_frame(int64_t pts, int64_t duration, movit::YCbCrLumaCoefficients ycbcr_coefficients, const std::vector<RefCountedFrame> &input_frames, GLuint *y_tex, GLuint *cbcr_tex);
65         RefCountedGLsync end_frame();
66         void shutdown();  // Blocking. Does not require an OpenGL context.
67         void release_gl_resources();  // Requires an OpenGL context. Must be run after shutdown.
68         int64_t global_delay() const;  // So we never get negative dts.
69
70 private:
71         std::unique_ptr<QuickSyncEncoderImpl> impl;
72 };
73
74 #endif