Skip to content

Commit

Permalink
added some TLC to the A/V decoders
Browse files Browse the repository at this point in the history
Fixes:
  . #51
  . #70
  . #71
  . #72
  • Loading branch information
jrdennisoss committed Mar 18, 2022
1 parent 29fe119 commit 2703537
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 20 deletions.
1 change: 1 addition & 0 deletions dosbox-0.74-3/include/reelmagic.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ struct ReelMagic_MediaPlayer {
virtual void SetDisplayPosition(const Bit16u x, const Bit16u y) = 0;
virtual void SetDisplaySize(const Bit16u width, const Bit16u height) = 0;
virtual void SetUnderVga(const bool value) = 0;
virtual void SetMagicDecodeKey(const Bit32u value) = 0;
virtual void SetLooping(const bool value) = 0;

virtual bool HasSystem() const = 0;
Expand Down
41 changes: 37 additions & 4 deletions dosbox-0.74-3/src/hardware/reelmagic_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,24 @@ static bool _unloadAllowed = true;



//global configuration parameters
namespace {
struct GlobalDefaultConfiguration {
bool underVga;
Bit32u magicDecodeKey;

void Reset() {
underVga = false;
magicDecodeKey = 0x40044041;
}
GlobalDefaultConfiguration() {Reset();}
};
static GlobalDefaultConfiguration _gdef;
};




// driver -> user callback function stuff...
namespace {
struct UserCallbackCall {
Expand Down Expand Up @@ -414,6 +432,7 @@ static void CleanupFromUserCallback(void) {

static Bit32u FMPDRV_EXE_driver_call(const Bit8u command, const Bit8u media_handle, const Bit16u subfunc, const Bit16u param1, const Bit16u param2) {
ReelMagic_MediaPlayer *player;
Bit32u rv;
switch(command) {
//
// Open Media Handle (File)
Expand All @@ -423,7 +442,14 @@ static Bit32u FMPDRV_EXE_driver_call(const Bit8u command, const Bit8u media_hand
if (((subfunc & 0xEFFF) != 1) && (subfunc != 2)) LOG(LOG_REELMAGIC, LOG_WARN)("subfunc not 1 or 2 on open command");
//if subfunc (or rather flags) has the 0x1000 bit set, then the first byte of the caller's
//pointer is the file path string length
return ReelMagic_NewPlayer(new ReelMagic_MediaPlayerDOSFile(param2, param1, (subfunc & 0x1000) != 0));
rv = ReelMagic_NewPlayer(new ReelMagic_MediaPlayerDOSFile(param2, param1, (subfunc & 0x1000) != 0));

//set player defaults from global...
player = &ReelMagic_HandleToMediaPlayer(rv);
player->SetUnderVga(_gdef.underVga);
player->SetMagicDecodeKey(_gdef.magicDecodeKey);

return rv;

//
// Close Media Handle
Expand Down Expand Up @@ -479,11 +505,17 @@ static Bit32u FMPDRV_EXE_driver_call(const Bit8u command, const Bit8u media_hand
case 0x0409:
case 0x040C:
case 0x040D:
return 0; //XXX need to implement these! return zero for now...
case 0x040E:
return 0; //unknown what all these currently do... callers seem to ignore the return value anyways...

rv = _gdef.underVga ? 4 : 2;
_gdef.underVga = param1 & 4;
LOG(LOG_REELMAGIC, LOG_NORMAL)("Setting Global Surface Z-Order To: %s VGA", _gdef.underVga ? "Under" : "Over");
return rv; //always return the last value...
case 0x0210: //XXX THIS IS THE MAGICAL F_CODE LOADER!!!
return 0; //for the user_callback() function... ignoring for now...
rv = _gdef.magicDecodeKey;
_gdef.magicDecodeKey = (param2 << 16) | param1;
LOG(LOG_REELMAGIC, LOG_NORMAL)("Setting Global Magical Decode Key to %08X", (unsigned)_gdef.magicDecodeKey);
return rv; //always return the last value...
}
}
else {
Expand Down Expand Up @@ -563,6 +595,7 @@ static Bit32u FMPDRV_EXE_driver_call(const Bit8u command, const Bit8u media_hand
ReelMagic_DeleteAllPlayers();
_userCallbackFarPtr = 0;
_userCallbackType = 0;
_gdef.Reset();
return 0;

//
Expand Down
26 changes: 10 additions & 16 deletions dosbox-0.74-3/src/hardware/reelmagic_pl_mpeg.h
Original file line number Diff line number Diff line change
Expand Up @@ -1534,7 +1534,7 @@ size_t plm_buffer_tell(plm_buffer_t *self) {

void plm_buffer_discard_read_bytes(plm_buffer_t *self) {
size_t byte_pos = self->bit_index >> 3;
if (byte_pos == self->length) {
if (byte_pos >= self->length) {
self->bit_index = 0;
self->length = 0;
}
Expand Down Expand Up @@ -1669,17 +1669,14 @@ int plm_buffer_has_start_code(plm_buffer_t *self, int code) {
return current;
}

int plm_buffer_no_start_code(plm_buffer_t *self) {
if (!plm_buffer_has(self, (5 << 3))) {
int plm_buffer_peek_non_zero(plm_buffer_t *self, int bit_count) {
if (!plm_buffer_has(self, bit_count)) {
return FALSE;
}

size_t byte_index = ((self->bit_index + 7) >> 3);
return !(
self->bytes[byte_index] == 0x00 &&
self->bytes[byte_index + 1] == 0x00 &&
self->bytes[byte_index + 2] == 0x01
);
int val = plm_buffer_read(self, bit_count);
self->bit_index -= bit_count;
return val != 0;
}

int16_t plm_buffer_read_vlc(plm_buffer_t *self, const plm_vlc_t *table) {
Expand Down Expand Up @@ -2607,7 +2604,6 @@ typedef struct plm_video_t {
int quantizer_scale;
int slice_begin;
int macroblock_address;
int slice_max_macroblock_address;

int mb_row;
int mb_col;
Expand Down Expand Up @@ -3014,7 +3010,6 @@ void plm_video_decode_picture(plm_video_t *self) {
void plm_video_decode_slice(plm_video_t *self, int slice) {
self->slice_begin = TRUE;
self->macroblock_address = (slice - 1) * self->mb_width - 1;
self->slice_max_macroblock_address = self->macroblock_address + self->mb_width;

// Reset motion vectors and DC predictors
self->motion_backward.h = self->motion_forward.h = 0;
Expand All @@ -3033,8 +3028,8 @@ void plm_video_decode_slice(plm_video_t *self, int slice) {
do {
plm_video_decode_macroblock(self);
} while (
self->macroblock_address < self->slice_max_macroblock_address &&
plm_buffer_no_start_code(self->buffer)
self->macroblock_address < self->mb_size - 1 &&
plm_buffer_peek_non_zero(self->buffer, 23)
);
}

Expand Down Expand Up @@ -3894,16 +3889,15 @@ int plm_audio_find_frame_sync(plm_audio_t *self) {
return TRUE;
}
}
self->buffer->bit_index = (i + 1) << 3;
self->buffer->bit_index = self->buffer->length << 3;
return FALSE;
}

int plm_audio_decode_header(plm_audio_t *self) {
plm_buffer_skip_bytes(self->buffer, 0x00);
if (!plm_buffer_has(self->buffer, 48)) {
return 0;
}

plm_buffer_skip_bytes(self->buffer, 0x00);
int sync = plm_buffer_read(self->buffer, 11);


Expand Down
3 changes: 3 additions & 0 deletions dosbox-0.74-3/src/hardware/reelmagic_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,9 @@ namespace { class ReelMagic_MediaPlayerImplementation : public ReelMagic_MediaPl
_underVga = value;
if (_playing) ReelMagic_PushVideoMixerUnderlayProvider(*this);
}
void SetMagicDecodeKey(const uint32_t value) {
//ignore for now...
}
void SetLooping(const bool value) {
_loop = value;
if (_plm != NULL) plm_set_loop(_plm, _loop ? TRUE : FALSE);
Expand Down

0 comments on commit 2703537

Please sign in to comment.