Keep max stream ID separate from current stream ID

This commit is contained in:
Jeffrey Pfau 2014-07-29 22:50:19 -07:00
parent 0023613625
commit 35bf1f3990
2 changed files with 14 additions and 5 deletions

View File

@ -38,6 +38,7 @@ bool GBARRSetStream(struct GBARRContext* rr, struct VDir* stream) {
rr->streamDir = stream; rr->streamDir = stream;
rr->movieStream = 0; rr->movieStream = 0;
rr->streamId = 1; rr->streamId = 1;
rr->maxStreamId = 1;
return true; return true;
} }
@ -58,24 +59,31 @@ bool GBARRLoadStream(struct GBARRContext* rr, uint32_t streamId) {
GBARRStopPlaying(rr); GBARRStopPlaying(rr);
} }
} }
rr->frames = 0;
rr->lagFrames = 0;
return true; return true;
} }
uint32_t GBARRIncrementStream(struct GBARRContext* rr) { bool GBARRIncrementStream(struct GBARRContext* rr) {
uint32_t newStreamId = rr->streamId + 1; uint32_t newStreamId = rr->maxStreamId + 1;
uint32_t oldStreamId = rr->streamId; uint32_t oldStreamId = rr->streamId;
if (GBARRIsRecording(rr) && rr->movieStream) { if (GBARRIsRecording(rr) && rr->movieStream) {
_emitTag(rr, rr->movieStream, TAG_END); _emitTag(rr, rr->movieStream, TAG_END);
_emitTag(rr, rr->movieStream, TAG_FRAME_COUNT);
rr->movieStream->write(rr->movieStream, &rr->frames, sizeof(rr->frames));
_emitTag(rr, rr->movieStream, TAG_LAG_COUNT);
rr->movieStream->write(rr->movieStream, &rr->lagFrames, sizeof(rr->lagFrames));
_emitTag(rr, rr->movieStream, TAG_NEXT_TIME); _emitTag(rr, rr->movieStream, TAG_NEXT_TIME);
rr->movieStream->write(rr->movieStream, &newStreamId, sizeof(newStreamId)); rr->movieStream->write(rr->movieStream, &newStreamId, sizeof(newStreamId));
} }
if (!GBARRLoadStream(rr, newStreamId)) { if (!GBARRLoadStream(rr, newStreamId)) {
return 0; return false;
} }
rr->maxStreamId = newStreamId;
_emitTag(rr, rr->movieStream, TAG_PREVIOUSLY); _emitTag(rr, rr->movieStream, TAG_PREVIOUSLY);
rr->movieStream->write(rr->movieStream, &oldStreamId, sizeof(oldStreamId)); rr->movieStream->write(rr->movieStream, &oldStreamId, sizeof(oldStreamId));
_emitTag(rr, rr->movieStream, TAG_BEGIN); _emitTag(rr, rr->movieStream, TAG_BEGIN);
return rr->streamId; return true;
} }
bool GBARRStartPlaying(struct GBARRContext* rr, bool autorecord) { bool GBARRStartPlaying(struct GBARRContext* rr, bool autorecord) {

View File

@ -31,6 +31,7 @@ struct GBARRContext {
uint32_t frames; uint32_t frames;
uint32_t lagFrames; uint32_t lagFrames;
uint32_t streamId; uint32_t streamId;
uint32_t maxStreamId;
// Streaming state // Streaming state
struct VDir* streamDir; struct VDir* streamDir;
@ -45,7 +46,7 @@ void GBARRContextDestroy(struct GBA*);
bool GBARRSetStream(struct GBARRContext*, struct VDir*); bool GBARRSetStream(struct GBARRContext*, struct VDir*);
bool GBARRLoadStream(struct GBARRContext*, uint32_t streamId); bool GBARRLoadStream(struct GBARRContext*, uint32_t streamId);
uint32_t GBARRIncrementStream(struct GBARRContext*); bool GBARRIncrementStream(struct GBARRContext*);
bool GBARRStartPlaying(struct GBARRContext*, bool autorecord); bool GBARRStartPlaying(struct GBARRContext*, bool autorecord);
void GBARRStopPlaying(struct GBARRContext*); void GBARRStopPlaying(struct GBARRContext*);