Skip to content
This repository was archived by the owner on Nov 8, 2021. It is now read-only.

Commit

Permalink
Fix switching to H.264.
Browse files Browse the repository at this point in the history
  • Loading branch information
polygraphene committed Jun 27, 2018
1 parent dcc463b commit dd9d063
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 198 deletions.
38 changes: 16 additions & 22 deletions app/src/main/cpp/nal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,19 +265,16 @@ bool processPacket(JNIEnv *env, char *buf, int len) {
// SPS + PPS has short size (8bytes + 28bytes in some environment), so we can assume SPS + PPS is contained in first fragment.

int zeroes = 0;
bool parsingSPS = true;
int SPSEnd = -1;
int PPSEnd = -1;
for (int i = pos + 4; i < len; i++) {
int foundNals = 0;
int end = -1;
for (int i = pos; i < len; i++) {
if (buf[i] == 0) {
zeroes++;
} else if (buf[i] == 1) {
if (zeroes == 3) {
if (parsingSPS) {
parsingSPS = false;
SPSEnd = i - 3;
} else {
PPSEnd = i - 3;
foundNals++;
if (foundNals >= 2) {
end = i - 3;
break;
}
}
Expand All @@ -286,30 +283,23 @@ bool processPacket(JNIEnv *env, char *buf, int len) {
zeroes = 0;
}
}
if (SPSEnd == -1 || PPSEnd == -1) {
if (end == -1) {
// Invalid frame.
LOG("Got invalid frame. Too large SPS or PPS?");
return false;
}
allocateBuffer(SPSEnd - pos, presentationTime, frameIndex);
push(buf + pos, SPSEnd - pos);
putNAL();

pos = SPSEnd;

allocateBuffer(PPSEnd - pos, presentationTime, frameIndex);
push(buf + pos, PPSEnd - pos);

allocateBuffer(end - pos, presentationTime, frameIndex);
push(buf + pos, end - pos);
putNAL();

pos = PPSEnd;
pos = end;

processingIDR = true;

// Allocate IDR frame buffer
allocateBuffer(header->frameByteSize - (PPSEnd - sizeof(VideoFrameStart)),
allocateBuffer(header->frameByteSize - (pos - sizeof(VideoFrameStart)),
presentationTime, frameIndex);
frameByteSize = header->frameByteSize - (PPSEnd - sizeof(VideoFrameStart));
frameByteSize = header->frameByteSize - (pos - sizeof(VideoFrameStart));
// Note that if previous frame packet has lost, we dispose that incomplete buffer implicitly here.
}else if(g_codec == ALVR_CODEC_H265 && NALType == H265_NAL_TYPE_VPS) {
int zeroes = 0;
Expand Down Expand Up @@ -477,3 +467,7 @@ void notifyNALWaitingThread(JNIEnv *env) {

pthread_cond_broadcast(&cond_nonzero);
}

void nalClearStopped() {
stopped = false;
}
1 change: 1 addition & 0 deletions app/src/main/cpp/nal.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ void recycleNal(JNIEnv *env, jobject nal);
int getNalListSize(JNIEnv *env);
void flushNalList(JNIEnv *env);
void notifyNALWaitingThread(JNIEnv *env);
void nalClearStopped();

#endif //ALVRCLIENT_NAL_H
6 changes: 6 additions & 0 deletions app/src/main/cpp/udp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -744,3 +744,9 @@ Java_com_polygraphene_alvr_UdpReceiverThread_getServerPort(JNIEnv *env, jobject
}
return 0;
}

extern "C"
JNIEXPORT void JNICALL
Java_com_polygraphene_alvr_UdpReceiverThread_clearStopped(JNIEnv *env, jobject instance) {
nalClearStopped();
}
Loading

0 comments on commit dd9d063

Please # to comment.