Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i have made a code in which i receive the live stream on my client from my Raspberry pi
on my Pi (server) i have used a netcat command

pi@raspberrypi ~ $ raspivid -t 0 -o - | nc -l 5001

on the receiver, i store the received data in a buffer, and then that buffer i pass it to my decoder to decode the received video stream


C#
#define IMAGE_BUF_SIZE 20480
#define INCOMING_BUF_SIZE  8192  
#define DECODER_BUFFER_SIZE 4096


int  totalsize= 0, count=0,recv_size = 0, recvSize;
char imagearray[IMAGE_BUF_SIZE], incomingarry[INCOMING_BUF_SIZE]; 
char * buffer = imagearray; // for buffer decoding logic
unsigned int bufferSize =sizeof(imagearray); // for buffer decoding logic

			do
			{
				do
				{
					recvSize = recv(socket, incomingarry, INCOMING_BUF_SIZE, 0);
					count++; // just to check the number of iterations for while loop.
				}while(recvSize < INCOMING_BUF_SIZE);
				
				for (int i=0; i&lt;recvSize; i++)
					imagearray[totalsize+i] = incomingarry[i];

				totalsize = recvSize + totalsize;
				recvSize = NULL;
			
			}while(totalsize < IMAGE_BUF_SIZE); 

		   bd.ptr = (uint8_t *)imagearray;
			bd.size = sizeof(imagearray);
			av_register_all();
			avformat_network_init();


i am getting an error stating
"Unhandled exception at 0x6B12F048 in realtimevideo.exe: 0xC0000005: Access violation (parameters: 0x00000008)."

at line
C++
recvSize = recv(socket, incomingarry, INCOMING_BUF_SIZE, 0);


i know that netcat is capable of sending maximum 8kb data.
n my decoder logic requires minimum 20kb of data to function.

What I have tried:

i tried different combinations of values like
#define IMAGE_BUF_SIZE 20480// 40960 //
#define INCOMING_BUF_SIZE 8192 //4096 //1024 //2048 //
#define DECODER_BUFFER_SIZE 4096 // 2048 // 8192 //

but it doesnt work.

even if the connection is successful, the decoder works for the 1st 10 frames and then displays an error stating data not available.

i feel there is an issue with the kind of buffers that i have chosen
Posted
Updated 19-May-16 4:54am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900