Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

264_enc: apply encode base class for AVC SVC-T #7

Open
wants to merge 10 commits into
base: vp8svct
Choose a base branch
from
1 change: 1 addition & 0 deletions common/nalreader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ bool NalReader::read(const uint8_t*& nal, int32_t& nalSize)
const uint8_t* nalEnd;
if (m_asWhole) {
nalEnd = m_end;
m_next = m_end;
} else {
nalEnd = searchNalStart();
}
Expand Down
27 changes: 18 additions & 9 deletions common/nalreader_unittest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,26 @@ const std::array<uint8_t, 39> g_data = {
0x12
};

const std::array<int32_t, 5> g_nsizes = {9, 4, 6, 12, 7};
const std::array<int32_t, 5> g_nsizes = { 6, 1, 3, 9, 4 };

NALREADER_TEST(ReadAsUnits) {
const uint8_t* nal;
int32_t offset(1), size;
const uint32_t start(3); //start code size
int32_t size; //NAL unit size
int32_t offset(1); //to skip 1 junk byte in g_data

NalReader reader(&g_data[0], g_data.size(), false);
NalReader reader(&g_data[0], g_data.size(), 0, false);

for (unsigned n(0); n < g_nsizes.size(); ++n) {
//For unit reads, the NalReader returns buffer contents between each
//start code prefix, start code prefix is not included in read result;
//"nal": buffer contents;
//"size": buffer length;
EXPECT_TRUE(reader.read(nal, size));
EXPECT_EQ(size, g_nsizes[n]);
for (int32_t i(0); i < size; ++i)
EXPECT_EQ(nal[i], g_data[i+offset]);
offset += size;
EXPECT_EQ(nal[i], g_data[i + offset + start]);
offset += (size + start);
}

EXPECT_FALSE(reader.read(nal, size));
Expand All @@ -75,14 +81,17 @@ NALREADER_TEST(ReadAsUnits) {
NALREADER_TEST(ReadAsWhole) {
const uint8_t* nal;
int32_t size;
const int32_t offset = 4; // 1 initial junk byte + first start code

NalReader reader(&g_data[0], g_data.size(), true);

NalReader reader(&g_data[0], g_data.size(), 0, true);
//For whole read, the NalReader returns entire buffer contents after
//first start code. That is, the first start code prefix is not included
//in the result.
EXPECT_TRUE(reader.read(nal, size));
EXPECT_EQ((size_t)size, g_data.size());
EXPECT_EQ((size_t)(size + offset), g_data.size());

for (int32_t i(0); i < size; ++i)
EXPECT_EQ(nal[i], g_data[i]);
EXPECT_EQ(nal[i], g_data[i + offset]);

EXPECT_FALSE(reader.read(nal, size));
}
Expand Down
50 changes: 34 additions & 16 deletions common/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@

#include <assert.h>
#include <ctype.h>
#include <sstream>
#include <string.h>
#include <sys/time.h>
#include <va/va.h>
#include <cstdlib>
#include <limits>

namespace YamiMediaCodec{

Expand Down Expand Up @@ -69,33 +72,39 @@ bool guessResolution(const char* filename, int& w, int& h)
STATE_END,
};
int state = STATE_START;
const char* p = filename;
std::string strFilename(filename);
const char* tokStart = NULL;
long width = 0;
long hight = 0;

w = h = 0;
while (*p != '\0') {
uint32_t i = 0;
for (i = 0; i < strFilename.length(); i++) {
switch (state) {
case STATE_START:
{
if (isdigit(*p)) {
tokStart = p;
if (isdigit(strFilename[i])) {
tokStart = &(strFilename[i]);
state = STATE_WDITH;
}
break;
}
case STATE_WDITH:
{
if (*p == 'x' || *p == 'X') {
if (strFilename[i] == 'x' || strFilename[i] == 'X') {
state = STATE_X;
sscanf(tokStart, "%d", &w);
} else if (!isdigit(*p)){
strFilename[i] = ' ';
width = std::strtol(tokStart, NULL, 10);
}
else if (!isdigit(strFilename[i])) {
state = STATE_START;
}
break;
}
case STATE_X:
{
if (isdigit(*p)) {
tokStart = p;
if (isdigit(strFilename[i])) {
tokStart = &(strFilename[i]);
state = STATE_HEIGHT;
} else {
state = STATE_START;
Expand All @@ -104,23 +113,32 @@ bool guessResolution(const char* filename, int& w, int& h)
}
case STATE_HEIGHT:
{
if (!isdigit(*p)) {
if (!isdigit(strFilename[i])) {
state = STATE_END;
sscanf(tokStart, "%d", &h);
strFilename[i] = ' ';
hight = std::strtol(tokStart, NULL, 10);
}
break;
}
}
if (state == STATE_END)
break;
p++;
}

//conner case
if (*p == '\0' && state == STATE_HEIGHT) {
if (!isdigit(*p)) {
sscanf(tokStart, "%d", &h);
}
if (strFilename.length() == i && state == STATE_HEIGHT)
hight = std::strtol(tokStart, NULL, 10);

long maxInt = std::numeric_limits<int>::max();
if (width > maxInt || hight > maxInt) {
w = 0;
h = 0;
}
else {
w = width;
h = hight;
}

return w && h;
}

Expand Down
9 changes: 9 additions & 0 deletions common/utils_unittest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,15 @@ UTILS_TEST(guessResolutionOverflow) {
EXPECT_FALSE(guessResolution(sstream.str().c_str(), w, h));
EXPECT_EQ(w, 0);
EXPECT_EQ(h, 0);

sstream.str("");
sstream << long(std::numeric_limits<int>::max()) * 2 + 3
<< "x"
<< long(std::numeric_limits<int>::max()) * 3 + 2;

EXPECT_FALSE(guessResolution(sstream.str().c_str(), w, h));
EXPECT_EQ(w, 0);
EXPECT_EQ(h, 0);
}

struct BppEntry {
Expand Down
7 changes: 7 additions & 0 deletions interface/VideoEncoderDefs.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ typedef enum {
#define VIDEO_PARAMS_QUALITYLEVEL_NONE 0
#define VIDEO_PARAMS_QUALITYLEVEL_MIN 1
#define VIDEO_PARAMS_QUALITYLEVEL_MAX 7
#define TEMPORAL_LAYER_LENGTH_MAX 32

typedef struct VideoEncOutputBuffer {
uint8_t *data;
Expand Down Expand Up @@ -151,6 +152,11 @@ typedef struct VideoFrameRate {
uint32_t frameRateNum;
uint32_t frameRateDenom;
}VideoFrameRate;
typedef struct VideoTemproalLayers {
//bitrate of the highest layer is VideoParamsCommon.rcParams.bitRate
uint8_t numLayersMinus1;
uint32_t bitRate[TEMPORAL_LAYER_LENGTH_MAX];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change this to NUM_TEMPLAYER_MAX.
add add following comment
//layer 0 bitrate is bitRate[0]
//...
//layer highest birate is VideoParamsCommon.rcParams.bitRate

} VideoTemproalLayers;

typedef struct VideoResolution {
uint32_t width;
Expand Down Expand Up @@ -213,6 +219,7 @@ typedef struct VideoParamsCommon {
uint8_t level;
VideoResolution resolution;
VideoFrameRate frameRate;
VideoTemproalLayers temporalLayers;
uint32_t intraPeriod;
uint32_t ipPeriod;
uint32_t numRefFrames;
Expand Down