forked from obsproject/libdshowcapture
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathencoder.hpp
86 lines (65 loc) · 2.04 KB
/
encoder.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
* Copyright (C) 2014 Hugh Bailey <obs.jim@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA
*/
#pragma once
#include "../dshowcapture.hpp"
#include "output-filter.hpp"
#include "capture-filter.hpp"
#include <string>
#include <vector>
#include <deque>
#include <mutex>
using namespace std;
struct EncodedData {
vector<unsigned char> data;
inline EncodedData() = default;
inline EncodedData(unsigned char *data_, size_t size)
{
data.resize(size);
memcpy(data.data(), data_, size);
}
};
namespace DShow {
struct HVideoEncoder {
ComPtr<IGraphBuilder> graph;
ComPtr<ICaptureGraphBuilder2> builder;
ComPtr<IMediaControl> control;
ComPtr<IBaseFilter> encoder;
ComPtr<IBaseFilter> device;
ComPtr<OutputFilter> output;
ComPtr<CaptureFilter> capture;
VideoEncoderConfig config;
mutex packetMutex;
deque<EncodedData> packets;
EncodedData curPacket;
deque<long long> ptsVals;
bool initialized = false;
bool active = false;
HVideoEncoder();
~HVideoEncoder();
bool SetupCrossbar();
void Receive(IMediaSample *s);
bool ConnectFilters();
bool SetupEncoder(IBaseFilter *filter);
bool SetConfig(VideoEncoderConfig &config);
bool Encode(unsigned char *frame[DSHOW_MAX_PLANES],
size_t linesize[DSHOW_MAX_PLANES], long long timestampStart,
long long timestampEnd, EncoderPacket &packet,
bool &new_packet);
};
};