Welcome to mirror list, hosted at ThFree Co, Russian Federation.

is_magical_asset.c « reelmagic « contrib - github.com/dosbox-staging/dosbox-staging.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5b036c4f4a22afe7005a02f36773b42936a2fdc9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
 *  Copyright (C) 2022 Jon Dennis
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#include <stdio.h>

#define PL_MPEG_IMPLEMENTATION
#include "./original_pl_mpeg.h"


int
main(int argc, char *argv[]) {
  unsigned frame_rate_code;
  unsigned format_ves;

  if (argc != 2) {
    fprintf(stderr, "Usage: %s INPUT_FILE\n", argv[0]);
    return 1;
  }

  plm_t *plm = plm_create_with_filename(argv[1]);
  if (!plm) {
    printf("Couldn't open file %s\n", argv[1]);
    return 1;
  }

  format_ves = 0;

  plm_set_audio_enabled(plm, FALSE);
  if (!plm->video_decoder) {
    format_ves = 1;
    if (plm->audio_decoder) {
      plm_audio_destroy(plm->audio_decoder);
      plm->audio_decoder = NULL;
    }
    plm_demux_rewind(plm->demux);
    plm->has_decoders = TRUE;
    plm->video_packet_type = PLM_DEMUX_PACKET_VIDEO_1;
    if (plm->video_decoder) plm_video_destroy(plm->video_decoder);
    plm->video_decoder = plm_video_create_with_buffer(plm->demux->buffer, FALSE);
  }
  plm_rewind(plm);

  if (plm_buffer_find_start_code(plm->video_decoder->buffer, PLM_START_SEQUENCE) == -1) {
    printf("Error likely not an MPEG-1 video!\n");
    plm_destroy(plm);
    return 1;
  }

  plm_buffer_skip(plm->video_decoder->buffer, 12); //skip width
  plm_buffer_skip(plm->video_decoder->buffer, 12); //skip height
  plm_buffer_skip(plm->video_decoder->buffer, 4);  //skip PAR
  frame_rate_code = plm_buffer_read(plm->video_decoder->buffer, 4);

  plm_destroy(plm);

  if (frame_rate_code & 0x8) {
    printf("Magical MPEG-1 %s asset detected. Frame rate code=0x%X\n", format_ves ? "ES" : "PS", frame_rate_code);
    return 0;
  }
  else if (frame_rate_code == 0) {
    printf("Bad MPEG-1 %s asset detected. Frame rate code=0x%X\n", format_ves ? "ES" : "PS", frame_rate_code);
  }
  else {
    printf("Normal MPEG-1 %s asset detected. Frame rate code=0x%X\n", format_ves ? "ES" : "PS", frame_rate_code);
  }

  return 1;
}