Skip to content

Commit e171cc3

Browse files
authored
Merge pull request #299 from alienatedsec/roleo_testing
Merging tested commits
2 parents db856f3 + b305a15 commit e171cc3

24 files changed

+478
-116
lines changed

src/h264grabber/h264grabber/h264grabber.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022 roleo.
2+
* Copyright (c) 2023 roleo.
33
*
44
* This program is free software: you can redistribute it and/or modify
55
* it under the terms of the GNU General Public License as published by
@@ -140,6 +140,10 @@
140140
#define FIFO_NAME_HIGH "/tmp/h264_high_fifo"
141141
#define FIFO_NAME_AAC "/tmp/aac_audio_fifo"
142142

143+
#define F_LINUX_SPECIFIC_BASE 1024
144+
#define F_SETPIPE_SZ (F_LINUX_SPECIFIC_BASE + 7)
145+
#define F_GETPIPE_SZ (F_LINUX_SPECIFIC_BASE + 8)
146+
143147
// Unused vars
144148
unsigned char IDR[] = {0x65, 0xB8};
145149
unsigned char NAL_START[] = {0x00, 0x00, 0x00, 0x01};
@@ -530,6 +534,10 @@ int main(int argc, char **argv) {
530534
fprintf(stderr, "Error opening fifo %s\n", FIFO_NAME_LOW);
531535
return -1;
532536
}
537+
if (fcntl(fileno(fOut), F_SETPIPE_SZ, 65536) != 65536) {
538+
fprintf(stderr, "Cannot set size of fifo\n");
539+
return -1;
540+
};
533541
} else if (resolution == RESOLUTION_HIGH) {
534542
unlink(FIFO_NAME_HIGH);
535543
if (mkfifo(FIFO_NAME_HIGH, mode) < 0) {
@@ -546,6 +554,10 @@ int main(int argc, char **argv) {
546554
fprintf(stderr, "Error opening fifo %s\n", FIFO_NAME_HIGH);
547555
return -1;
548556
}
557+
if (fcntl(fileno(fOut), F_SETPIPE_SZ, 262144) != 262144) {
558+
fprintf(stderr, "Cannot set size of fifo\n");
559+
return -1;
560+
};
549561
} else if (resolution == RESOLUTION_AUDIO) {
550562
unlink(FIFO_NAME_AAC);
551563
if (mkfifo(FIFO_NAME_AAC, mode) < 0) {
@@ -562,6 +574,10 @@ int main(int argc, char **argv) {
562574
fprintf(stderr, "Error opening fifo %s\n", FIFO_NAME_AAC);
563575
return -1;
564576
}
577+
if (fcntl(fileno(fOut), F_SETPIPE_SZ, 8192) != 8192) {
578+
fprintf(stderr, "Cannot set size of fifo\n");
579+
return -1;
580+
};
565581
}
566582
}
567583

src/rRTSPServer/Makefile.rRTSPServer

100755100644
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
##### Change the following for your environment:
2-
COMPILE_OPTS = $(INCLUDES) -I. -I./include -O2 -ffunction-sections -fdata-sections -DSOCKLEN_T=socklen_t -D_LARGEFILE_SOURCE=1 -D_FILE_OFFSET_BITS=64 -DNO_OPENSSL=1 -DRTP_PAYLOAD_MAX_SIZE=1352 -DNEWLOCALE_NOT_USED
2+
COMPILE_OPTS = $(INCLUDES) -I. -I./include -O1 -ffunction-sections -fdata-sections -DSOCKLEN_T=socklen_t -D_LARGEFILE_SOURCE=1 -D_FILE_OFFSET_BITS=64 -DNO_OPENSSL=1 -DRTP_PAYLOAD_MAX_SIZE=1352 -DNEWLOCALE_NOT_USED
33
C = c
44
C_COMPILER = $(CC)
55
C_FLAGS = $(COMPILE_OPTS) $(CPPFLAGS) $(CFLAGS)
@@ -73,7 +73,7 @@ livemedia:
7373

7474
rRTSPServer_OBJS = src/rRTSPServer.$(OBJ) \
7575
src/ADTSAudioFifoServerMediaSubsession.$(OBJ) src/ADTSAudioFifoSource.$(OBJ) \
76-
src/DummySink.$(OBJ) src/ByteStreamFifoSource.$(OBJ) src/H264VideoFifoServerMediaSubsession.$(OBJ) \
76+
src/ByteStreamFifoSource.$(OBJ) src/H264VideoFifoServerMediaSubsession.$(OBJ) \
7777

7878
rRTSPServer$(EXE): $(rRTSPServer_OBJS) $(LOCAL_LIBS)
7979
$(LINK)$@ $(CONSOLE_LINK_OPTS) $(rRTSPServer_OBJS) $(LIBS) -lpthread

src/rRTSPServer/include/ADTSAudioFifoServerMediaSubsession.hh

100755100644
File mode changed.

src/rRTSPServer/include/ADTSAudioFifoSource.hh

100755100644
File mode changed.

src/rRTSPServer/include/ByteStreamFifoSource.hh

100755100644
File mode changed.

src/rRTSPServer/include/H264VideoFifoServerMediaSubsession.hh

100755100644
File mode changed.

src/rRTSPServer/include/presentationTime.hh

100755100644
File mode changed.

src/rRTSPServer/src/ADTSAudioFifoServerMediaSubsession.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ along with this library; if not, write to the Free Software Foundation, Inc.,
2020
// Implementation
2121

2222
#include "ADTSAudioFifoServerMediaSubsession.hh"
23+
#include "ADTSAudioStreamDiscreteFramer.hh"
2324
#include "ADTSAudioFifoSource.hh"
2425
#include "MPEG4GenericRTPSink.hh"
2526
#include "FramedFilter.hh"

src/rRTSPServer/src/ADTSAudioFifoSource.cpp

Lines changed: 63 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -212,90 +212,94 @@ void ADTSAudioFifoSource::doReadFromFile() {
212212
#else
213213
if (read(fileno(fFid), headers, sizeof headers) < (signed) sizeof headers) {
214214
#endif
215-
// The input source has ended:
216-
handleClosure();
217-
return;
218-
}
215+
fFrameSize = 0;
216+
fNumTruncatedBytes = 0;
217+
// // The input source has ended:
218+
// handleClosure();
219+
// return;
220+
} else {
219221

220-
// Extract important fields from the headers:
221-
Boolean protection_absent = headers[1]&0x01;
222-
u_int16_t frame_length
223-
= ((headers[3]&0x03)<<11) | (headers[4]<<3) | ((headers[5]&0xE0)>>5);
224-
u_int16_t syncword = (headers[0]<<4) | (headers[1]>>4);
225-
if (debug & 4) fprintf(stderr, "Read frame: syncword 0x%x, protection_absent %d, frame_length %d\n", syncword, protection_absent, frame_length);
226-
if (syncword != 0xFFF) {
227-
fprintf(stderr, "WARNING: Bad syncword! Try to recover sync.\n");
228-
// Resync
229-
while (1) {
222+
// Extract important fields from the headers:
223+
Boolean protection_absent = headers[1]&0x01;
224+
u_int16_t frame_length
225+
= ((headers[3]&0x03)<<11) | (headers[4]<<3) | ((headers[5]&0xE0)>>5);
226+
u_int16_t syncword = (headers[0]<<4) | (headers[1]>>4);
227+
if (debug & 4) fprintf(stderr, "Read frame: syncword 0x%x, protection_absent %d, frame_length %d\n", syncword, protection_absent, frame_length);
228+
if (syncword != 0xFFF) {
229+
fprintf(stderr, "WARNING: Bad syncword! Try to recover sync.\n");
230+
// Resync
231+
while (1) {
230232
#ifdef READ_FROM_FILES_SYNCHRONOUSLY
231-
fread(headers, 1, 1, fFid);
233+
fread(headers, 1, 1, fFid);
232234
#else
233-
read(fileno(fFid), headers, 1);
235+
read(fileno(fFid), headers, 1);
234236
#endif
235-
if (headers[0] == 0xFF) {
237+
if (headers[0] == 0xFF) {
236238
#ifdef READ_FROM_FILES_SYNCHRONOUSLY
237-
fread(&headers[1], 1, 1, fFid);
239+
fread(&headers[1], 1, 1, fFid);
238240
#else
239-
read(fileno(fFid), &headers[1], 1);
241+
read(fileno(fFid), &headers[1], 1);
240242
#endif
241-
// Check the 'syncword':
242-
if ((headers[1]&0xF0) == 0xF0) {
243+
// Check the 'syncword':
244+
if ((headers[1]&0xF0) == 0xF0) {
243245
#ifdef READ_FROM_FILES_SYNCHRONOUSLY
244-
fread(&headers[2], 1, sizeof(headers) - 2, fFid);
246+
fread(&headers[2], 1, sizeof(headers) - 2, fFid);
245247
#else
246-
read(fileno(fFid), &headers[2], sizeof(headers) - 2);
248+
read(fileno(fFid), &headers[2], sizeof(headers) - 2);
247249
#endif
248-
break;
250+
break;
251+
}
249252
}
253+
usleep(1000);
250254
}
251-
usleep(10000);
252255
}
253-
}
254-
unsigned numBytesToRead
255-
= frame_length > sizeof headers ? frame_length - sizeof headers : 0;
256+
unsigned numBytesToRead
257+
= frame_length > sizeof headers ? frame_length - sizeof headers : 0;
256258

257-
// If there's a 'crc_check' field, skip it:
258-
if (!protection_absent) {
259-
unsigned char null[2];
259+
// If there's a 'crc_check' field, skip it:
260+
if (!protection_absent) {
261+
unsigned char null[2];
260262
#ifdef READ_FROM_FILES_SYNCHRONOUSLY
261-
fread(null, 1, 2, fFid);
263+
fread(null, 1, 2, fFid);
262264
#else
263-
read(fileno(fFid), null, 2);
265+
read(fileno(fFid), null, 2);
264266
#endif
265-
numBytesToRead = numBytesToRead > 2 ? numBytesToRead - 2 : 0;
266-
}
267+
numBytesToRead = numBytesToRead > 2 ? numBytesToRead - 2 : 0;
268+
}
267269

268-
// Next, read the raw frame data into the buffer provided:
269-
if (numBytesToRead > fMaxSize) {
270-
fNumTruncatedBytes = numBytesToRead - fMaxSize;
271-
numBytesToRead = fMaxSize;
272-
}
270+
// Next, read the raw frame data into the buffer provided:
271+
if (numBytesToRead > fMaxSize) {
272+
fNumTruncatedBytes = numBytesToRead - fMaxSize;
273+
numBytesToRead = fMaxSize;
274+
}
273275
#ifdef READ_FROM_FILES_SYNCHRONOUSLY
274-
int numBytesRead = fread(fTo, 1, numBytesToRead, fFid);
276+
int numBytesRead = fread(fTo, 1, numBytesToRead, fFid);
275277
#else
276-
int numBytesRead = read(fileno(fFid), fTo, numBytesToRead);
278+
int numBytesRead = read(fileno(fFid), fTo, numBytesToRead);
277279
#endif
278-
if (numBytesRead < 0) numBytesRead = 0;
279-
fFrameSize = numBytesRead;
280-
fNumTruncatedBytes += numBytesToRead - numBytesRead;
281-
282-
// Set the 'presentation time':
283-
if (fPresentationTime.tv_sec == 0 && fPresentationTime.tv_usec == 0) {
284-
// This is the first frame, so use the current time:
285-
gettimeofday(&fPresentationTime, NULL);
286-
} else {
280+
if (numBytesRead < 0) numBytesRead = 0;
281+
fFrameSize = numBytesRead;
282+
fNumTruncatedBytes += numBytesToRead - numBytesRead;
283+
284+
// Set the 'presentation time':
285+
if (fPresentationTime.tv_sec == 0 && fPresentationTime.tv_usec == 0) {
286+
// This is the first frame, so use the current time:
287+
gettimeofday(&fPresentationTime, NULL);
288+
} else {
287289
#ifndef PRES_TIME_CLOCK
288-
// Increment by the play time of the previous frame:
289-
unsigned uSeconds = fPresentationTime.tv_usec + fuSecsPerFrame;
290-
fPresentationTime.tv_sec += uSeconds/1000000;
291-
fPresentationTime.tv_usec = uSeconds%1000000;
290+
// Increment by the play time of the previous frame:
291+
unsigned uSeconds = fPresentationTime.tv_usec + fuSecsPerFrame;
292+
fPresentationTime.tv_sec += uSeconds/1000000;
293+
fPresentationTime.tv_usec = uSeconds%1000000;
292294
#else
293-
// Use system clock to set presentation time
294-
gettimeofday(&fPresentationTime, NULL);
295+
// Use system clock to set presentation time
296+
gettimeofday(&fPresentationTime, NULL);
295297
#endif
296-
}
298+
}
299+
if (debug & 4) fprintf(stderr, "AAC frame - fPresentationTime, sec = %ld, usec = %ld\n", fPresentationTime.tv_sec, fPresentationTime.tv_usec);
297300

298-
fDurationInMicroseconds = fuSecsPerFrame;
301+
fDurationInMicroseconds = fuSecsPerFrame;
302+
}
299303

300304
// Switch to another task, and inform the reader that he has data:
301305
#ifdef READ_FROM_FILES_SYNCHRONOUSLY

src/rRTSPServer/src/ByteStreamFifoSource.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ along with this library; if not, write to the Free Software Foundation, Inc.,
2727

2828
////////// ByteStreamFifoSource //////////
2929

30+
extern int debug;
31+
3032
ByteStreamFifoSource*
3133
ByteStreamFifoSource::createNew(UsageEnvironment& env, char const* fileName,
3234
unsigned preferredFrameSize,
@@ -170,7 +172,9 @@ void ByteStreamFifoSource::doReadFromFile() {
170172
// We don't know a specific play time duration for this data,
171173
// so just record the current time as being the 'presentation time':
172174
gettimeofday(&fPresentationTime, NULL);
175+
fDurationInMicroseconds = fPlayTimePerFrame;
173176
}
177+
if (debug & 4) fprintf(stderr, "h264 frame - fPresentationTime, sec = %ld, usec = %ld\n", fPresentationTime.tv_sec, fPresentationTime.tv_usec);
174178

175179
// Inform the reader that he has data:
176180
#ifdef READ_FROM_FILES_SYNCHRONOUSLY

0 commit comments

Comments
 (0)