FFMpeg undefined reference to get_buffer - c++

I'm trying to upgrade the FFMpeg source used with one of our projects but get_buffer has gone away. I'm not 100% sure on which method to replace it with. Here are two contexts in which its used, any help is appreciated.
I look forward to hearing from you soon,
Thanks,
Kevin
cur_offset = avio_tell(pb);
if (!para->playctrl_info.read_end_flag && (0 == pkt->data_size)) {
rev_byte = get_buffer(pb, pbuf, para->max_raw_size);
if ((rev_byte > 0) && (cur_offset <= para->pFormatCtx->data_offset)) {
try_count = 0;
pkt->data_size = rev_byte;
para->read_size.total_bytes += rev_byte;
pkt->avpkt_newflag = 1;
pkt->avpkt_isvalid = 1;
do {
read_length = get_buffer(s->pb, data + 12, read_size);
if ((read_length <= 0) || (sync_flag == 1024)) {
if (read_length == AVERROR(EAGAIN)) {
continue;
} else {
FREE(data);
log_error("[%s]get data failed. ret=%d\n", __FUNCTION__, read_length);
return 0;
}
} else {
break;
}
} while (retry_get_data < am_p->playctrl_info.read_max_retry_cnt);
pkt = data;

Although you already found your answer I will provide an answer in case others have the same issue. durandal_1707 provided the answer to you (I assume) in #ffmpeg-devel IRC:
expresspotato: I'm having trouble integrating the latest version of
ffmpeg against an old one from about a year and a half ago. It appears
get_buffer defined in aviobuf.c has gone away. Do you know which
method I should replace it with?
durandal_1707: in e63a362857d9807b23e65872598d782fa53bb6af get_buffer
have been renamed to avio_read

Related

Could anyone teach me on how to unpack the return value?

below is the code which had writted in c++ and basically what this function do would be pack the value into hex and unpack the return value in hex
abc_API_API long __stdcall ABC_ExecuteCommand(slngCommandParameter *lngCmdPrmCode, shexRespData *hexRespData, sRespData *Data)
{
long lngResult, lngRtn;
char strMsg[512];
memset((void*)strMsg, '\0', sizeof(strMsg));
shexCommandParameter hexCmdPrmCode;
try {
sCmdData cmdData;
PBYTE pbRDTBuff;
PDWORD pcbRDTLength;
PCRSTATUS lpStatus;
MappingTable(&hexCmdPrmCode, lngCmdPrmCode);
sprintf_s(strMsg, "Command : [%X]%s", hexCmdPrmCode.HexCommandCode, hexCmdPrmCode.Command.c_str());
WriteLog(strMsg);
sprintf_s(strMsg, "Parameter: [%X]%s", hexCmdPrmCode.HexParameterCode, hexCmdPrmCode.Parameter.c_str());
WriteLog(strMsg);
cmdData.bCMDByte1 = 'C';
cmdData.bCMDByte2 = 'D';
char *lpCMPBuff = new char[lngCmdPrmCode->lngDataSize + 1];
lpCMPBuff[(lngCmdPrmCode->lngDataSize)] = '\0';
cmdData.cbCMPLength = USHORT(lngCmdPrmCode->lngDataSize);
if (lngCmdPrmCode->lngDataSize > 0)
PackBCDHex(lpCMPBuff, strRemoveSpace(lngCmdPrmCode->strData), (lngCmdPrmCode->lngDataSize) * 2);
cmdData.pbCMPBuff = LPBYTE(lpCMPBuff);
lngResult = F3_ExecCommand (g_Reader, cmdData.bCMDByte1, cmdData.bCMDByte2 , cmdData.pbCMPBuff, cmdData.cbCMPLength, pbRDTBuff, pcbRDTLength, lpStatus);
if(lngResult == F3_S_SUCCESS) {
lngRtn = 0;
} else {
lngRtn = -1;
}
Data->ErrCode = (long)lngResult;
Data->Message = SysAllocStringByteLen(strMsg, strlen(strMsg));
WriteLog(strMsg);
return lngRtn;
} catch (exception& e) {
sprintf_s(strMsg, "Exception#ABC_DeniedInsertion: %s", e.what());
WriteError(strMsg);
return -1;
}
}
but i had no clue on how to properly unpack the data which suppose to put in this line
if(lngResult == F3_S_SUCCESS) {
lngRtn = 0;
} else {
lngRtn = -1;
}
below would the the unpack function which would be used
UnpackBCDHex
what i know is when lngResult is equal to 0 which means success, then the pbRDTBuff would point to the buff of the response data,and when pcbRDTLength >0 then i would need to assign an array and put the data in and using UnpackBCDHex to unpack it. but i have no clue on how can i achieve it. can anyone can guide me or showing me which document i can refer to finish this function?
thank you
HI, The problem had been solved. Thank you for all the help.Really really appreciate for those who willing spend their time and inbox chating with me teaching me step by step and trying to help me figure out the issue together.I really love this community which is such beginner friendly.Love u all 3000 haha

Using SQLFetchScroll to insert data

I'm trying to insert into a table data using SQLFetchScroll. The problem is if I set ROWSET_SIZE to 2, for example, of 1000 lines from source I only insert 500 lines (half) into destination table. I think the problem is with the function SQLExecute but I can't figure out how to set it right. Does anyone know how to solve this, please?
const SQLUSMALLINT ROWSET_SIZE = 2;
SQLSetStmtAttr(srcHStmt, SQL_ATTR_ROW_ARRAY_SIZE, (SQLPOINTER)ROWSET_SIZE, 0);
SQLLEN FetchOffset = 0;
while (TRUE)
{
srcReturn = SQLFetchScroll(srcHStmt, SQL_FD_FETCH_NEXT, FetchOffset);
if (srcReturn == SQL_NO_DATA_FOUND || srcReturn == SQL_ERROR)
{
if (srcReturn == SQL_ERROR) showError(SQL_HANDLE_DBC, srcHDBC);
break;
}
dstReturn = SQLExecute(dstHStmt);
}
Compiler: VS2015 / 64 bit machine.
When using SQL_FETCH_RELATIVE I'm having the same results.
SQLExecDirect(...);
SQLLEN FetchOffset = 2;
while (TRUE)
{
srcReturn = SQLFetchScroll(srcHStmt, SQL_FETCH_RELATIVE, FetchOffset);
if (srcReturn == SQL_NO_DATA_FOUND || srcReturn == SQL_ERROR)
{
if (srcReturn == SQL_ERROR) showError(SQL_HANDLE_DBC, srcHDBC);
break;
}
dstReturn = SQLExecute(dstHStmt);
}

How to find out the next time when the clock will be adjusted for Daylight Saving?

I'm curious, if there's any way to find out the UTC date/time when the next Daylight Saving adjustment will take place?
Something akin to what Windows reports (see circled):
This information is provided in Windows by the EnumDynamicTimeZoneInformation function.
See http://msdn.microsoft.com/en-us/library/windows/desktop/hh706893%28v=vs.85%29.aspx
There is a database that has code and data: http://www.iana.org/time-zones
I don't think there's a specific API for this. I would just do a binary search, using localtime (and maybe time and mktime) from <ctime> (C++) or <time.h> (C).
A basic approach is to scan ahead three months at a time until the tm_isdst flag in the returned data structure is flipped. Then you can start binary searching between the last two two dates to figure out exactly when it flips.
See http://www.cplusplus.com/reference/ctime/tm/ for reference material.
I appreciate all your replies. And, yes, indeed I was asking about a WinAPI for Windows.
I did more research and came up with the following method that does what I wanted. It uses C++ and MFC's COleDateTime for easier date/time calculations. Other than that it's just C++ and WinAPIs. Please check if I understood the documentation for the DYNAMIC_TIME_ZONE_INFORMATION correctly. Here's the code:
int GetNextDaylightSavingAdjustmentTime(SYSTEMTIME* pOutDtNextDST_Local, int* pnOutAdjustmentMin)
{
//Get next time when DST adjustment will take place
//'pOutDtNextDST_Local' = if not NULL, receives the (local) time when next DST adjustment will take place
//'pnOutAdjustmentMin' = if not NULL, receives the amount of adjustment in minutes
//RETURN:
// = 1 if got the time, or
// = 0 if DST is not used
// = -1 if error (check GetLastError() for info)
int nOSError = NO_ERROR;
//Load API dynamically (in case of Windows XP)
BOOL (WINAPI *pfnGetDynamicTimeZoneInformation)(PDYNAMIC_TIME_ZONE_INFORMATION);
(FARPROC&)pfnGetDynamicTimeZoneInformation =
::GetProcAddress(::GetModuleHandle(L"Kernel32.dll"), "GetDynamicTimeZoneInformation");
DWORD tzID;
SYSTEMTIME StandardDate;
SYSTEMTIME DaylightDate;
int nBiasDaylight;
//Use newer API if possible
if(pfnGetDynamicTimeZoneInformation)
{
DYNAMIC_TIME_ZONE_INFORMATION dtzi = {0};
tzID = pfnGetDynamicTimeZoneInformation(&dtzi);
StandardDate = dtzi.StandardDate;
DaylightDate = dtzi.DaylightDate;
nBiasDaylight = dtzi.DaylightBias;
}
else
{
//Older API
TIME_ZONE_INFORMATION tzi = {0};
tzID = GetTimeZoneInformation(&tzi);
StandardDate = tzi.StandardDate;
DaylightDate = tzi.DaylightDate;
nBiasDaylight = tzi.DaylightBias;
}
int nRes = -1;
int nAdjMins = 0;
SYSTEMTIME stDstChange;
memset(&stDstChange, 0, sizeof(stDstChange));
SYSTEMTIME stDst;
if(tzID == TIME_ZONE_ID_STANDARD ||
tzID == TIME_ZONE_ID_DAYLIGHT)
{
stDst = tzID != TIME_ZONE_ID_DAYLIGHT ? DaylightDate : StandardDate;
if(stDst.wMonth >= 1 &&
stDst.wMonth <= 12 &&
stDst.wDay >= 1 &&
stDst.wDayOfWeek >= 0 &&
stDst.wDayOfWeek <= 6)
{
//Get adjustment bias
nAdjMins = tzID != TIME_ZONE_ID_DAYLIGHT ? -nBiasDaylight : nBiasDaylight;
if(stDst.wYear == 0)
{
//Relative date
SYSTEMTIME stLocal;
::GetLocalTime(&stLocal);
//Begin from the 1st day of the month &
//make sure that the date is in the future
COleDateTime dt;
for(int nYear = stLocal.wYear;; nYear++)
{
dt.SetDateTime(nYear, stDst.wMonth, 1, stDst.wHour, stDst.wMinute, stDst.wSecond);
if(dt > COleDateTime::GetCurrentTime())
break;
}
int nRequiredWeek = stDst.wDay >= 1 && stDst.wDay <= 5 ? stDst.wDay : 5;
for(int nCntDOW = 1;;)
{
//0=Sunday, 1=Monday; 2=Tuesday; 3=Wednesday; 4=Thursday; 5=Friday; 6=Saturday
int dow = dt.GetDayOfWeek() - 1;
ASSERT(dow >= 0 && dow <= 6);
if(dow == stDst.wDayOfWeek)
{
if(nCntDOW >= nRequiredWeek)
{
//Stop
break;
}
else
{
nCntDOW++;
}
}
//Go to next day
dt += COleDateTimeSpan(1, 0, 0, 0);
}
//Convert back to system time
if(dt.GetAsSystemTime(stDstChange))
{
//Success
nRes = 1;
}
else
{
//Failed
nOSError = ERROR_INVALID_FUNCTION;
ASSERT(NULL);
}
}
else
{
//Absolute date
stDstChange = stDst;
nRes = 1;
}
}
else
{
//Failed
nOSError = ERROR_INVALID_PARAMETER;
ASSERT(NULL);
}
}
else
{
//DST is not used
if(tzID == TIME_ZONE_ID_UNKNOWN)
{
nRes = 0;
}
else
{
//Error
nOSError = ERROR_INVALID_DATA;
ASSERT(NULL);
}
}
if(pOutDtNextDST_Local)
*pOutDtNextDST_Local = stDstChange;
if(pnOutAdjustmentMin)
*pnOutAdjustmentMin = nAdjMins;
::SetLastError(nOSError);
return nRes;
}
PS. And scratch my request for the UTC time. As I learned, it is easier to deal with local time in this situation.

SDL2 + ffmpeg2 intermittent clicks instead of audio

Using c++, SDL2, SDL2_mix, ffmpeg2.
Inited SDL2_mix with callback
Mix_HookMusic(MusicPlayer, &g_audioPos);
Decoded audio from ogg to AVFrame* by this code:
while(av_read_frame(m_formatContext, &m_packet) >= 0)
{
if(m_packet.stream_index == m_audioStream)
{
int audio_frame_finished;
avcodec_decode_audio4(m_audioCodecContext, m_audioFrame, &audio_frame_finished, &m_packet);
if(!audio_frame_finished)
{
continue;
}
}
}
After this code i have frame with some m_audioFrame->data[0] and m_audioFrame->linesize[0] == 4096
Once in a while my callback being called:
void MusicPlayer(void *_udata, Uint8 *_stream, int _len)
{
if(!g_audioData)
{
return;
}
AudioData* audio = reinterpret_cast<AudioData*>(g_audioData);
if(!audio || audio->Frame->linesize[0] == 0)
{
return;
}
SDL_memcpy((Uint8*)audio->Data + audio->Pos, (Uint8*)audio->Frame->data[0], audio->Frame->linesize[0]);
audio->Pos+= audio->Frame->linesize[0];
int rest = g_chunkSize - audio->Pos;//frame->linesize[0];
if(rest <= 0)
{
SDL_memcpy(_stream, audio->Data, _len);
audio->Pos = 0;
*(int*)_udata += _len;
}
}
_len == 8192, so i must push 2 frames to fill stream, but all i get - clicks in my speaker. What am i doing wrong?
PS: Tried to reopen MIX with Mix_OpenAudio(m_audioCodecContext->sample_rate, AUDIO_S16SYS, m_audioCodecContext->channels, 4096);. Interesting thing is m_audioCodecContext->channels == 2 and when my callback being called _len = 16384. Have no idea what to do. Please help!!!
You did not show how you perform the ffmpeg initialization; I'd speculate you forgot to specify the requested sample format:
aCodecCtx->request_sample_fmt = AV_SAMPLE_FMT_S16;
Take a look at the source code of my Karaoke lyrics editor which uses the SDL/ffmpeg audio player based on the latest ffmpeg (and hence decode_audio4): https://sourceforge.net/p/karlyriceditor/code/HEAD/tree/src/audioplayerprivate.cpp

Can Allegro update the number of joysticks at runtime?

Is there a way to update the number of joysticks plugged in at run-time other than constantly calling remove_joystick() then install_joystick? This proves to be extremely slow (goes from 60 FPS to around 5).
Allegro 4.2 answers only please...
void Joystick::Update() {
//If joystick input was lost, attempt to reacquire.
if(GetNumJoysticks() == 0) {
throw InputNotAvailableException("Joystick");
}
//If all joysticks were deleted remove input and do nothing.
if(_numjoysticks == 0) {
remove_joystick();
return;
}
//Update state information
if(poll_joystick() < 0) {
throw InputNotAvailableException("Joystick");
}
for(int i = 0; i < _numButtons; ++i) {
_prevButtons[i].b = _curButtons[i].b;
_prevButtons[i].name = _curButtons[i].name;
_curButtons[i].b = joy[_joyNumber].button[i].b;
_curButtons[i].name = joy[_joyNumber].button[i].name;
}
for(int i = 0; i < _numSticks; ++i) {
for(int j = 0; j < joy[_joyNumber].stick[i].num_axis; ++j) {
_prevSticks[i].axis[j].name = _curSticks[i].axis[j].name;
_prevSticks[i].axis[j].pos = _curSticks[i].axis[j].pos;
_prevSticks[i].axis[j].d1 = _curSticks[i].axis[j].d1;
_prevSticks[i].axis[j].d2 = _curSticks[i].axis[j].d2;
_curSticks[i].axis[j].name = joy[_joyNumber].stick[i].axis[j].name;
_curSticks[i].axis[j].pos = joy[_joyNumber].stick[i].axis[j].pos;
_curSticks[i].axis[j].d1 = joy[_joyNumber].stick[i].axis[j].d1;
_curSticks[i].axis[j].d2 = joy[_joyNumber].stick[i].axis[j].d2;
}
_prevSticks[i].flags = _curSticks[i].flags;
_prevSticks[i].name = _curSticks[i].name;
_curSticks[i].flags = joy[_joyNumber].stick[i].flags;
_curSticks[i].name = joy[_joyNumber].stick[i].name;
}
}
int Joystick::GetNumJoysticks() {
remove_joystick();
if(install_joystick(JOY_TYPE_DIRECTX)) {
return 0;
}
return (num_joysticks);
}
The 4.x series does not. The 5.x series does.
You'll have to either listen for native OS events using custom platform specific code (assuming such things exist) and only call the Allegro deinit/init functions when a change is detected, or require the user to initiate joystick refresh manually.
Under Linux, you could inotify_add_watch() /dev/input to check for changes. Looking at the 4.4 Allegro code, looks like you'd want to call the Win32 functions joyGetNumDevs() and joyGetPos(). Something like:
int WIN_MAX_JOYSTICKS = joyGetNumDevs(); // this should never change
JOYINFO ji;
int pluggedin_count = 0;
for (int i = 0; i < WIN_MAX_JOYSTICKS; ++i)
if (joyGetPos(i, &ji) == JOYERR_NOERROR) ++pluggedin_count;
if (pluggedin_count != last_pluggedin_count) /* reinit Allegro */
You'd have to do that every N seconds.
Those joy* functions are Windows functions, so read MSDN docs to learn how to use them.