mirror of
https://github.com/mpromonet/v4l2rtspserver
synced 2024-11-17 21:25:40 +00:00
improve JPEG quantization table
This commit is contained in:
parent
2243e62fc6
commit
570ff43e78
@ -40,7 +40,7 @@ class MJPEGVideoSource : public JPEGVideoSource
|
|||||||
int headerSize = 0;
|
int headerSize = 0;
|
||||||
bool headerOk = false;
|
bool headerOk = false;
|
||||||
fFrameSize = 0;
|
fFrameSize = 0;
|
||||||
|
|
||||||
for (unsigned int i = 0; i < frameSize ; ++i)
|
for (unsigned int i = 0; i < frameSize ; ++i)
|
||||||
{
|
{
|
||||||
// SOF
|
// SOF
|
||||||
@ -53,13 +53,13 @@ class MJPEGVideoSource : public JPEGVideoSource
|
|||||||
// DQT
|
// DQT
|
||||||
if ( (i+5+64) < frameSize && (fTo[i] == 0xFF) && (fTo[i+1] == 0xDB))
|
if ( (i+5+64) < frameSize && (fTo[i] == 0xFF) && (fTo[i+1] == 0xDB))
|
||||||
{
|
{
|
||||||
int quantSize = fTo[i+3];
|
unsigned int quantSize = fTo[i+3]-4;
|
||||||
int quantIdx = fTo[i+4];
|
unsigned int quantIdx = fTo[i+4];
|
||||||
if (quantIdx < 3)
|
if (quantSize*quantIdx+quantSize <= sizeof(m_qTable))
|
||||||
{
|
{
|
||||||
if ( quantIdx+1 > m_qTableCount )
|
memcpy(m_qTable + quantSize*quantIdx, fTo + i + 5, quantSize);
|
||||||
m_qTableCount = quantIdx+1;
|
if (quantSize*quantIdx+quantSize > m_qTableSize)
|
||||||
memcpy(m_qTable + quantIdx*64, fTo + i + 5, 64);
|
m_qTableSize = quantSize*quantIdx+quantSize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// End of header
|
// End of header
|
||||||
@ -90,9 +90,9 @@ class MJPEGVideoSource : public JPEGVideoSource
|
|||||||
{
|
{
|
||||||
length = 0;
|
length = 0;
|
||||||
precision = 0;
|
precision = 0;
|
||||||
if (m_qTableCount > 0)
|
if (m_qTableSize > 0)
|
||||||
{
|
{
|
||||||
length = 64*m_qTableCount;
|
length = m_qTableSize;
|
||||||
}
|
}
|
||||||
return m_qTable;
|
return m_qTable;
|
||||||
}
|
}
|
||||||
@ -100,7 +100,7 @@ class MJPEGVideoSource : public JPEGVideoSource
|
|||||||
protected:
|
protected:
|
||||||
MJPEGVideoSource(UsageEnvironment& env, FramedSource* source) : JPEGVideoSource(env),
|
MJPEGVideoSource(UsageEnvironment& env, FramedSource* source) : JPEGVideoSource(env),
|
||||||
m_inputSource(source),
|
m_inputSource(source),
|
||||||
m_width(0), m_height(0), m_qTableCount(0),
|
m_width(0), m_height(0), m_qTableSize(0),
|
||||||
m_type(0)
|
m_type(0)
|
||||||
{
|
{
|
||||||
memset(&m_qTable,0,sizeof(m_qTable));
|
memset(&m_qTable,0,sizeof(m_qTable));
|
||||||
@ -114,7 +114,7 @@ class MJPEGVideoSource : public JPEGVideoSource
|
|||||||
FramedSource* m_inputSource;
|
FramedSource* m_inputSource;
|
||||||
u_int8_t m_width;
|
u_int8_t m_width;
|
||||||
u_int8_t m_height;
|
u_int8_t m_height;
|
||||||
u_int8_t m_qTable[64*3];
|
u_int8_t m_qTable[128*2];
|
||||||
int m_qTableCount;
|
unsigned int m_qTableSize;
|
||||||
u_int8_t m_type;
|
u_int8_t m_type;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user