Hi,
Please find the code as an attachment.
Thanks
On 8/12/10, Ronald S. Bultje <[email protected]> wrote:
> Hi,
>
> On Wed, Aug 11, 2010 at 2:30 PM, Umakant Goyal <[email protected]>
> wrote:
>> I believe,i am feeding Quicktime/ISO data to libavcodec for decoding.
>> No i am not using libavformat to demux the file. What i am doing,
>> capturing data using capture card, encoding it using libavcodec and
>> sending it over network using own RTP Stack.
>> Othe node that is also developed by us, is receiving RTP data and
>> feeding it to decoder module (libavcodec) after remving RTP Header (12
>> Bytes).
> [..]
>> On 8/9/10, Ronald S. Bultje <[email protected]> wrote:
>>> [..] please show us all
>>> (ALL, no single line excluded) code that you use to set up the
>>> AVCodecContext for MPEG-4 video decoding.
>
> I think I've asked 3 times now: please provide the code that you use
> to setup the AVCodecContext for decoding. I can't help without that.
> ;-).
>
> Ronald
> _______________________________________________
> libav-user mailing list
> [email protected]
> https://lists.mplayerhq.hu/mailman/listinfo/libav-user
>
#include <stdio.h>
#define inline _inline
#define inline _inline
extern "C"
{
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
}
AVCodecContext* pContext;
AVCodec* pCodec;
int giRTPSock;
bool GetRTPPacket ()
{
struct sockaddr_in gstTempAddr;
int iAddrLen;
iAddrLen = sizeof(struct sockaddr_in);
while (1)
{
unsigned char tempBuf [5000] = {0,};
unsigned char acMediaBuff [1500], int aiMediaBuffLen = 1500;
aiMediaBuffLen = recvfrom(giRTPSock, (char*)acMediaBuff,
aiMediaBuffLen, 0, (struct sockaddr *) &gstTempAddr,
&iAddrLen);
cout << "Recd RTP data of length--" <<aiMediaBuffLen <<endl;
/* Striping off RTP Header 12 Bytes */
aiMediaBuffLen = aiMediaBuffLen - 12;
memcpy (tempBuf, (acMediaBuff + 12), aiMediaBuffLen);
/* Here just for testing we are making sure one frame will not
split into multiples RTP packes */
AVFrame *pFrame = avcodec_alloc_frame();
if (NULL == pFrame)
{
return false;
}
else
{
int size;
int retVal = avcodec_decode_video (pContext, pFrame,
&size, tempBuf, aiMediaBuffLen);
if (retVal <= 0)
{
LogDump ("Fail to Decode");
return false;
}
}
}
}
bool OpenDecoder ()
{
pContext = avcodec_alloc_context();
if (NULL == pContext)
{
return false;
}
else
{
pContext->codec_id = CODEC_ID_MPEG4;
pContext->codec_type = CODEC_TYPE_VIDEO;
pContext->width = 192;
pContext->height = 242;
/* open it */
if (avcodec_open (pContext, pCodec) < 0)
{
return false;
}
return true;
}
}
bool InitSocket()
{
struct sockaddr_in stRTPAddr;
//Open RTP Socket
giRTPSock = socket(AF_INET, SOCK_DGRAM, 0);
if (giRTPSock < 0)
{
return false;
}
memset(&stRTPAddr, 0, sizeof(stRTPAddr));
stRTPAddr.sin_addr.s_addr = inet_addr("127.0.0.1");
stRTPAddr.sin_family = AF_INET;
stRTPAddr.sin_port = htons(22222);
//Bind Socket with RTP Address
if (bind(*giRTPSock,(struct sockaddr*) &stRTPAddr,
sizeof(stRTPAddr)) == -1)
{
cout<< "RTP Socket Binding Error\n";
closesocket(giRTPSock);
return false;
} else {
cout<< "Succesfully Binded" <<endl;
}
return true;
}
int main(int argc, char *argv[])
{
WSADATA dat;
WSAStartup(MAKEWORD(2,2),&dat);
avcodec_init();
avcodec_register_all();
if (true == InitSocket ())
{
pCodec = avcodec_find_decoder (CODEC_ID_MPEG4);
if (NULL == pCodec)
{
return -1;
}
if (true == OpenDecoder ())
{
GetRTPPacket ();
}
}
return 0;
}
_______________________________________________
libav-user mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user