Skip to content

Commit f48150f

Browse files
committed
Merging changes from DEE 5.2 release.
1 parent d6d188b commit f48150f

12 files changed

Lines changed: 107 additions & 45 deletions

File tree

plugins/code/common/PipingManager/PipingManager.cpp

Lines changed: 63 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include <limits>
4141
#include <PipingManager.h>
4242

43+
4344
#ifdef WIN32
4445
#ifndef NOMINMAX
4546
#define NOMINMAX
@@ -56,10 +57,11 @@
5657

5758
#define DEFAULT_TIMEOUT (10000)
5859
#define DEFAULT_BUFFER (1024*128)
59-
#define NAMED_PIPE_BUFFER (1024*64)
60-
#define WRITE_SIZE (16*1024)
61-
#define READ_SIZE (16*1024)
60+
#define NAMED_PIPE_BUFFER (128*1024)
61+
#define WRITE_SIZE (64*1024)
62+
#define READ_SIZE (64*1024)
6263

64+
static const auto cvtimeout = std::chrono::milliseconds(50);
6365

6466
using namespace std::chrono;
6567
using std::vector;
@@ -188,6 +190,11 @@ struct PipeData
188190
bool mConnected;
189191
#endif
190192

193+
std::condition_variable mInBufHasData;
194+
std::condition_variable mInBufHasRoom;
195+
std::condition_variable mOutBufHasData;
196+
std::condition_variable mOutBufHasRoom;
197+
191198
PipeData(std::string name, size_t maxbuf, pipe_type_t type, int id, bool client = false);
192199
~PipeData();
193200
void closeThread();
@@ -212,41 +219,53 @@ int get_flag(pipe_type_t type)
212219
}
213220
#endif
214221

222+
223+
static bool stopWaitingForIQAvailable(PipeData* p) {
224+
return (p->mInBuf.Taken() > 0);
225+
}
226+
215227
static
216228
int pipe_write_func(PipeData* data)
217229
{
218230
piping_status_t status = PIPE_MGR_OK;
231+
std::unique_lock<std::mutex> lck(data->mMutex);
232+
data->mInBufHasData.wait_for(lck, cvtimeout, std::bind(stopWaitingForIQAvailable, data));
219233

220-
data->mMutex.lock();
221234
size_t writeSize = data->mInBuf.Taken();
222235
if (writeSize > WRITE_SIZE) writeSize = WRITE_SIZE;
223236
data->mInBuf.PeekFront(data->mTempBuf.data(), writeSize);
224-
data->mMutex.unlock();
237+
lck.unlock();
225238

226239
#ifdef WIN32
227240
DWORD bytes_written = 0;
228-
if (WriteFile(data->mHandle, data->mTempBuf.data(), (DWORD)writeSize, &bytes_written, NULL) == FALSE)
229-
{
230-
DWORD last_error = GetLastError();
231-
data->mErrorString = std::to_string(last_error);
232-
status = PIPE_MGR_WRITE_ERROR;
241+
if (writeSize > 0) {
242+
if (WriteFile(data->mHandle, data->mTempBuf.data(), (DWORD)writeSize, &bytes_written, NULL) == FALSE)
243+
{
244+
DWORD last_error = GetLastError();
245+
data->mErrorString = std::to_string(last_error);
246+
status = PIPE_MGR_WRITE_ERROR;
247+
}
233248
}
234249
#else
235-
int bytes_written = write(data->mHandle, data->mTempBuf.data(), writeSize);
236-
if (bytes_written < 0)
237-
{
238-
if (errno != EAGAIN)
250+
int bytes_written = 0;
251+
if (writeSize > 0) {
252+
bytes_written = write(data->mHandle, data->mTempBuf.data(), writeSize);
253+
if (bytes_written < 0)
239254
{
240-
data->mErrorString = "write returned " + std::to_string(bytes_written) + " (errno=" + std::to_string((int)errno) + ").";
241-
status = PIPE_MGR_WRITE_ERROR;
255+
if (errno != EAGAIN)
256+
{
257+
data->mErrorString = "write returned " + std::to_string(bytes_written) + " (errno=" + std::to_string((int)errno) + ").";
258+
status = PIPE_MGR_WRITE_ERROR;
259+
}
260+
bytes_written = 0;
242261
}
243-
bytes_written = 0;
244262
}
245263
#endif
246264
if (bytes_written > 0)
247265
{
248266
data->mMutex.lock();
249267
data->mInBuf.PopFront(bytes_written);
268+
data->mInBufHasRoom.notify_all();
250269
data->mMutex.unlock();
251270
data->mTotalDataWritten += bytes_written;
252271
}
@@ -258,11 +277,18 @@ int pipe_write_func(PipeData* data)
258277
return -1;
259278
}
260279

280+
static bool stopWaitingForOQFree(PipeData* p) {
281+
return (p->mOutBuf.Free() > 0);
282+
}
283+
261284
static
262285
int pipe_read_func(PipeData* data)
263286
{
264287
piping_status_t status = PIPE_MGR_OK;
288+
std::unique_lock<std::mutex> lck(data->mMutex);
289+
data->mOutBufHasRoom.wait_for(lck, cvtimeout, std::bind(stopWaitingForOQFree, data));
265290
size_t readSize = data->mOutBuf.Free();
291+
lck.unlock();
266292
if (readSize > READ_SIZE) readSize = READ_SIZE;
267293
if (readSize == 0) return 0;
268294

@@ -301,6 +327,7 @@ int pipe_read_func(PipeData* data)
301327
{
302328
data->mMutex.lock();
303329
data->mOutBuf.Append(data->mTempBuf.data(), bytes_read);
330+
data->mOutBufHasData.notify_all();
304331
data->mMutex.unlock();
305332
}
306333

@@ -354,7 +381,6 @@ void pipe_thread_func(PipeData* data)
354381
int written_bytes = 0;
355382
int read_bytes = 0;
356383
bool success= true;
357-
358384
// run main thread loop
359385
while (data->mStop == false)
360386
{
@@ -386,9 +412,11 @@ void pipe_thread_func(PipeData* data)
386412
break;
387413
}
388414

415+
#if 1
389416
if (written_bytes == 0 && read_bytes == 0) {
390417
std::this_thread::sleep_for(std::chrono::microseconds(100));
391418
}
419+
#endif
392420
}
393421

394422
#ifdef WIN32
@@ -688,6 +716,11 @@ piping_status_t PipingManager::getPipePath(int pipe_id, std::string& path)
688716
}
689717
}
690718

719+
720+
static bool stopWaitingForIQFree(PipeData* p) {
721+
return (p->mInBuf.Free() > 0);
722+
}
723+
691724
piping_status_t PipingManager::writeToPipe(int pipe_id, void* buffer, size_t data_size, size_t& bytes_written)
692725
{
693726
piping_status_t status = PIPE_MGR_OK;
@@ -701,7 +734,9 @@ piping_status_t PipingManager::writeToPipe(int pipe_id, void* buffer, size_t dat
701734
else
702735
{
703736
PipeData* pipe = it->second;
704-
std::lock_guard<std::mutex> lock(pipe->mMutex);
737+
738+
std::unique_lock<std::mutex> lck(pipe->mMutex);
739+
pipe->mInBufHasRoom.wait_for(lck, cvtimeout, std::bind(stopWaitingForIQFree, pipe));
705740

706741
size_t data_to_write = data_size;
707742
if (data_to_write > pipe->mInBuf.Free())
@@ -717,6 +752,7 @@ piping_status_t PipingManager::writeToPipe(int pipe_id, void* buffer, size_t dat
717752
{
718753
pipe->mInBuf.Append((char*)buffer, data_to_write);
719754
bytes_written = data_to_write;
755+
pipe->mInBufHasData.notify_all();
720756
}
721757

722758
status = pipe->mTimeout ? PIPE_MGR_TIMEOUT : status;
@@ -725,6 +761,10 @@ piping_status_t PipingManager::writeToPipe(int pipe_id, void* buffer, size_t dat
725761
return status;
726762
}
727763

764+
static bool stopWaitingForOQAvailable(PipeData* p) {
765+
return (p->mOutBuf.Taken() > 0);
766+
}
767+
728768
piping_status_t PipingManager::readFromPipe(int pipe_id, void* buffer, size_t buffer_size, size_t& bytes_read)
729769
{
730770
piping_status_t status = PIPE_MGR_OK;
@@ -737,7 +777,9 @@ piping_status_t PipingManager::readFromPipe(int pipe_id, void* buffer, size_t bu
737777
else
738778
{
739779
PipeData* pipe = it->second;
740-
std::lock_guard<std::mutex> lock(pipe->mMutex);
780+
781+
std::unique_lock<std::mutex> lck(pipe->mMutex);
782+
pipe->mOutBufHasData.wait_for(lck, cvtimeout, std::bind(stopWaitingForOQAvailable, pipe));
741783

742784
size_t data_to_read = buffer_size;
743785
if (data_to_read > pipe->mOutBuf.Taken())
@@ -749,6 +791,7 @@ piping_status_t PipingManager::readFromPipe(int pipe_id, void* buffer, size_t bu
749791
{
750792
pipe->mOutBuf.PopFront((char*)buffer, data_to_read);
751793
bytes_read = data_to_read;
794+
pipe->mOutBufHasRoom.notify_all();
752795
}
753796

754797
status = pipe->mTimeout ? PIPE_MGR_TIMEOUT : pipe->mStatus;

plugins/code/common/PipingManager/PipingManager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
*/
3232

3333
#include <string>
34+
#include <condition_variable>
3435

3536
struct PipingManagerData;
3637

plugins/code/hevc_enc/beamr/src/hevc_enc_beamr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ static const PropertyInfo propertyInfo[] = {
5050
{"width", PROPERTY_TYPE_INTEGER, NULL, NULL, NULL, 1, 1, ACCESS_TYPE_WRITE_INIT},
5151
{"height", PROPERTY_TYPE_INTEGER, NULL, NULL, NULL, 1, 1, ACCESS_TYPE_WRITE_INIT},
5252
{"color_space", PROPERTY_TYPE_STRING, NULL, "i420", "i400:i420:i422:i444", 0, 1, ACCESS_TYPE_WRITE_INIT},
53-
{"frame_rate", PROPERTY_TYPE_DECIMAL, NULL, NULL, "23.976:24:25:29.97:30:48:50:59.94:60", 1, 1,
53+
{"frame_rate", PROPERTY_TYPE_DECIMAL, NULL, NULL, "23.976:24:25:29.97:30:48:50:59.94:60:119.88:120", 1, 1,
5454
ACCESS_TYPE_WRITE_INIT},
5555
{"data_rate", PROPERTY_TYPE_INTEGER, "Average data rate in kbps.", "15000", NULL, 0, 1, ACCESS_TYPE_WRITE_INIT},
5656
{"max_vbv_data_rate", PROPERTY_TYPE_INTEGER, "Max VBV ctrl rate in kbps.", "15000", NULL, 0, 1,

plugins/code/hevc_enc/beamr/src/hevc_enc_beamr_impl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ void Encoder::parseGopStructureFile() {
642642
continue;
643643
}
644644

645-
if (s.type != VH3_SLICE_B && s.type != VH3_SLICE_P && s.type != VH3_SLICE_I && s.type != -1) {
645+
if (s.type != VH3_SLICE_B && s.type != VH3_SLICE_P && s.type != VH3_SLICE_I && s.type != VH3_SLICE_UNKNOWN) {
646646
message("gop_structure_in_file: Ignoring line %llu. Invalid 'type' value.", lineNum);
647647
continue;
648648
}

plugins/code/hevc_enc/beamr/src/hevc_enc_beamr_utils.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,14 @@ FramePeriod string2FramePeriod(const std::string& s) {
148148
fp.timeScale = 60;
149149
fp.numUnitsInTick = 1;
150150
}
151+
else if ("119.88" == s) {
152+
fp.timeScale = 120000;
153+
fp.numUnitsInTick = 1001;
154+
}
155+
else if ("120" == s) {
156+
fp.timeScale = 120;
157+
fp.numUnitsInTick = 1;
158+
}
151159
return fp;
152160
}
153161

plugins/code/hevc_enc/ffmpeg/src/hevc_enc_ffmpeg.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ PropertyInfo hevc_enc_ffmpeg_info[] =
5050
, { "width", PROPERTY_TYPE_INTEGER, NULL, NULL, NULL, 1, 1, ACCESS_TYPE_WRITE_INIT }
5151
, { "height", PROPERTY_TYPE_INTEGER, NULL, NULL, NULL, 1, 1, ACCESS_TYPE_WRITE_INIT }
5252
, { "color_space", PROPERTY_TYPE_STRING, NULL, "i420", "i400:i420:i422:i444", 0, 1, ACCESS_TYPE_WRITE_INIT }
53-
, { "frame_rate", PROPERTY_TYPE_DECIMAL, NULL, NULL, "23.976:24:25:29.97:30:48:50:59.94:60", 1, 1, ACCESS_TYPE_WRITE_INIT }
53+
, { "frame_rate", PROPERTY_TYPE_DECIMAL, NULL, NULL, "23.976:24:25:29.97:30:48:50:59.94:60:119.88:120", 1, 1, ACCESS_TYPE_WRITE_INIT }
5454
, { "data_rate", PROPERTY_TYPE_INTEGER, "Average data rate in kbps.", "15000", NULL, 0, 1, ACCESS_TYPE_WRITE_INIT }
5555
, { "max_vbv_data_rate", PROPERTY_TYPE_INTEGER, "Max VBV data rate in kbps.", "15000", NULL, 0, 1, ACCESS_TYPE_WRITE_INIT }
5656
, { "vbv_buffer_size", PROPERTY_TYPE_INTEGER, "VBV buffer size in kb.", "30000", NULL, 0, 1, ACCESS_TYPE_WRITE_INIT }

plugins/code/hevc_enc/ffmpeg/src/hevc_enc_ffmpeg_utils.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,7 @@ fps_to_num_denom
817817
if ("23.976" == fps) return "24000/1001";
818818
else if ("29.97" == fps) return "30000/1001";
819819
else if ("59.94" == fps) return "60000/1001";
820+
else if ("119.88" == fps) return "120000/1001";
820821
return std::to_string(std::stoi(fps))+"/1";
821822
}
822823

plugins/code/hevc_enc/x265/readme.txt

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
Dolby Encoding Engine plugin for the x265 HEVC encoder
22

3-
The provided source code was built and tested using the x265 library version 3.1.2.
3+
The provided source code was built and tested using the x265 library version 3.5.
44

55
Build tools:
6-
- Visual Studio 2013 (to build x265 library)
7-
- Visual Studio 2013 or 2015 (to build the plugin)
6+
- Visual Studio 2015
87
- gcc 4.8.5
8+
- clang 12.0.0
99

1010
x265 compilation and prerequisities:
1111
- CMake
@@ -14,38 +14,44 @@ x265 compilation and prerequisities:
1414
Make sure cmake is added to PATH
1515

1616
- NASM:
17-
x265 shall be built with NASM (verified with 2.13.03) in order to achieve maximum performance.
17+
x265 shall be built with NASM (verified with 2.15.05) in order to achieve maximum performance.
1818
NASM Release Builds are currently stored at www.nasm.us/pub/nasm/releasebuilds/
19-
Linux:
19+
Linux & Mac:
2020
- Download:
21-
wget www.nasm.us/pub/nasm/releasebuilds/2.13.03/nasm-2.13.03.tar.xz
21+
wget www.nasm.us/pub/nasm/releasebuilds/2.15.05/nasm-2.13.05.tar.xz
2222
- Extract:
23-
tar -xvf nasm-2.13.03.tar.xz
24-
- Go to the extracted nasm-2.13.03 directory, build and install:
23+
tar -xvf nasm-2.15.05.tar.xz
24+
- Go to the extracted nasm-2.15.05 directory, build and install:
2525
./configure
2626
make
2727
sudo make install
2828
Windows:
2929
- Download the installer:
30-
https://www.nasm.us/pub/nasm/releasebuilds/2.13.03/win64/nasm-2.13.03-installer-x64.exe
30+
https://www.nasm.us/pub/nasm/releasebuilds/2.15.05/win64/nasm-2.15.05-installer-x64.exe
3131
- Execute the installer and follow the instructions
3232
- Add the NASM installation directory to PATH
3333

3434
- Building x265:
3535
It is mandatory to build the x265 library with at least 10-bit API.
3636
The recommended way is to build an x265 library containing 8/10/12-bit API.
3737
The simplest way is to use the x265 multilib build scripts.
38-
39-
Linux:
40-
./multilib.sh (in x265_3.1.2/build/linux directory)
38+
Linux & Mac:
39+
./make-Makefiles.bash (If building for Mac, set CMAKE_OSX_DEPLOYMENT_TARGET value to 10.12)
40+
41+
./multilib.sh (in x265_3.5/build/linux directory)
4142

4243
Windows:
43-
.\multilib.bat (in x265_3.1.2\vc12-x86_64)
44+
.\multilib.bat (in x265_3.5\vc12-x86_64 if building in VS2013, in x265_3.5\vc15-x86_64 if VS2015 or later)
45+
If builing with VS2015, change %VS150COMNTOOLS% in build-all.bat and multilib.bat to %VS140COMNTOOLS%
46+
and change occurances of -G "Visual Studio 15 Win64" to -G "Visual Studio 14 Win64" in build-all.bat, make-solutions.bat, multilib.bat
47+
or refer to resources/engineering_docs/x265_build_and_install/BuildAndInstallx265Plugin.md
4448

4549
If you set up NASM properly, at the start of execution, the following message displays:
46-
Found nasm: C:/Users/[USER]/NASM/nasm.exe (found version "2.13.03")
47-
Found Nasm 2.13.03 to build assembly primitives
48-
x265 version 3.1.2
50+
Found nasm: C:/Users/[USER]/NASM/nasm.exe (found version "2.15.05")
51+
Found Nasm 2.15.05 to build assembly primitives
52+
x265 version 3.5
53+
54+
Generated libraries can be found in /8bit (/8bit/Release if Windows) directory
4955

5056
Visit https://bitbucket.org/multicoreware/x265/wiki/Home for more details.
5157

@@ -75,5 +81,5 @@ Build instructions, Linux:
7581
2. Build using make/hevc_enc_x265/linux_amd64_gnu/Makefile
7682
- make hevc_enc_x265_release.so
7783
3. Copy the .so library with the plugin and "libx265.so" to the Dolby Encoding Engine installation folder
78-
4. Rename "libx265.so" (or create a symbolic link) according to the used x265 API version, e.g. "libx265.so.176"
79-
- To check what the expected name is, use the command: ldd hevc_enc_x265_release.so
84+
4. Rename "libx265.so" (or create a symbolic link) according to the used x265 API version, e.g. "libx265.so.199"
85+
- To check what the expected name is, use the command: ldd hevc_enc_x265_release.so, or check the number in x265_config.h file

plugins/code/hevc_enc/x265/src/hevc_enc_x265.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ PropertyInfo hevc_enc_x265_info[] =
4848
,{"width", PROPERTY_TYPE_INTEGER, NULL, NULL, NULL, 1, 1, ACCESS_TYPE_WRITE_INIT}
4949
,{"height", PROPERTY_TYPE_INTEGER, NULL, NULL, NULL, 1, 1, ACCESS_TYPE_WRITE_INIT}
5050
,{"color_space", PROPERTY_TYPE_STRING, NULL, "i420", "i400:i420:i422:i444", 0, 1, ACCESS_TYPE_WRITE_INIT}
51-
,{"frame_rate", PROPERTY_TYPE_DECIMAL, NULL, NULL, "23.976:24:25:29.97:30:48:50:59.94:60", 1, 1, ACCESS_TYPE_WRITE_INIT}
51+
,{"frame_rate", PROPERTY_TYPE_DECIMAL, NULL, NULL, "23.976:24:25:29.97:30:48:50:59.94:60:119.88:120", 1, 1, ACCESS_TYPE_WRITE_INIT}
5252
,{"data_rate", PROPERTY_TYPE_INTEGER, "Average data rate in kbps.", "15000", NULL, 0, 1, ACCESS_TYPE_WRITE_INIT}
5353
,{"max_vbv_data_rate", PROPERTY_TYPE_INTEGER, "Max VBV data rate in kbps.", "15000", NULL, 0, 1, ACCESS_TYPE_WRITE_INIT}
5454
,{"vbv_buffer_size", PROPERTY_TYPE_INTEGER, "VBV buffer size in kb.", "30000", NULL, 0, 1, ACCESS_TYPE_WRITE_INIT}
@@ -80,7 +80,7 @@ PropertyInfo hevc_enc_x265_info[] =
8080
,{ "force_slice_type", PROPERTY_TYPE_BOOLEAN, "Indicates that framework will try to force specific slice type.", "false", NULL, 0, 1, ACCESS_TYPE_WRITE_INIT }
8181

8282
// Only properties below (ACCESS_TYPE_USER) can be modified
83-
,{"preset", PROPERTY_TYPE_STRING, "Sets parameters to preselected values.", "medium", "ultrafast:superfast:veryfast:faster:fast:medium:slow:slower:veryslow:placebo", 0, 1, ACCESS_TYPE_USER}
83+
,{"preset", PROPERTY_TYPE_STRING, "Sets parameters to preselected values.", "medium", "placebo:veryslow:slower:slow:medium:fast:faster:veryfast:superfast:ultrafast", 0, 1, ACCESS_TYPE_USER}
8484
,{"tune", PROPERTY_TYPE_STRING, "Tune the settings for a particular type of source or situation.", "none", "none:psnr:ssim:grain:fastdecode:zerolatency", 0, 1, ACCESS_TYPE_USER}
8585
,{"open_gop", PROPERTY_TYPE_BOOLEAN, "Allows I-slices to be non-IDR.", "false", NULL, 0, 1, ACCESS_TYPE_USER}
8686
,{"max_intra_period", PROPERTY_TYPE_INTEGER, "Max intra period in frames.", "25", "1:65535", 0, 1, ACCESS_TYPE_USER}

plugins/code/hevc_enc/x265/src/hevc_enc_x265_utils.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,8 @@ parse_init_params
291291
&& value != "50"
292292
&& value != "59.94"
293293
&& value != "60"
294+
&& value != "119.88"
295+
&& value != "120"
294296
)
295297
{
296298
state->data->msg += "\nInvalid 'frame_rate' value.";
@@ -1147,5 +1149,6 @@ fps_to_num_denom
11471149
if ("23.976" == fps) return {24000,1001};
11481150
else if ("29.97" == fps) return {30000,1001};
11491151
else if ("59.94" == fps) return {60000, 1001};
1152+
else if ("119.88" == fps) return {120000, 1001};
11501153
else return {std::stoi(fps), 1};
11511154
}

0 commit comments

Comments
 (0)