File: mpegscan2.c

package info (click to toggle)
vcdimager 2.0.1%2Bdfsg-6
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, trixie
  • size: 4,352 kB
  • sloc: ansic: 17,957; sh: 4,828; xml: 317; makefile: 282; cpp: 58
file content (119 lines) | stat: -rw-r--r-- 2,879 bytes parent folder | download | duplicates (4)
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*
    $Id$

    Copyright (C) 2001, 2005 Herbert Valerio Riedel <hvr@gnu.org>

    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
*/

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <cdio/cdio.h>
#include <cdio/bytesex.h>

/* Private haeaders */
#include "mpeg.h"
#include "mpeg_stream.h"
#include "stream_stdio.h"

static inline
void _dump_msf (const msf_t *__msf)
{
  msf_t _msf = *__msf;

  if (_msf.m != 0xff)
    {
      _msf.s &= 0x7f;
      _msf.f &= 0x7f;
    }
	  
  printf (" %.2x:%.2x.%.2x ", 
	  _msf.m, _msf.s, _msf.f);
}

int 
main (int argc, const char *argv[])
{
  VcdMpegSource_t *src;
  unsigned packets, packet_no;
  VcdMpegStreamCtx ctx;

  if (argc != 2)
    return 1;

  src = vcd_mpeg_source_new (vcd_data_source_new_stdio (argv[1]));

  vcd_mpeg_source_scan (src, true, true,  NULL, NULL);

  packets = vcd_mpeg_source_get_info (src)->packets;

  printf ("packets: %d\n", packets);

  memset (&ctx, 0, sizeof (ctx));

  ctx.stream.scan_data_warnings = VCD_MPEG_SCAN_DATA_WARNS + 1;

  printf ("cur_ofs  (lba) aps prev_ofs  next_ofs  back_ofs  forw_ofs\n");

  for (packet_no = 0; packet_no < packets; packet_no++)
    {
      /* struct vcd_mpeg_packet_flags pkt_flags; */
      char buf[2324];

      vcd_mpeg_source_get_packet (src, packet_no,
				  buf, /* &pkt_flags */ NULL, false);

      vcd_mpeg_parse_packet (&buf, 2324, true, &ctx);

      if (ctx.packet.scan_data_ptr)
	{
	  struct vcd_mpeg_scan_data_t *sd = ctx.packet.scan_data_ptr;
	  msf_t _msf;

	  cdio_lba_to_msf (packet_no, &_msf);

	  printf ("%.2x:%.2x.%.2x (%4d) %d ",
		  _msf.m, _msf.s, _msf.f,
		  packet_no, ctx.packet.aps);

	  _dump_msf (&sd->prev_ofs);
	  _dump_msf (&sd->next_ofs);

	  _dump_msf (&sd->back_ofs);
	  _dump_msf (&sd->forw_ofs);

	  printf ("\n");
	}
    }

  {
    const struct vcd_mpeg_stream_info *_info = vcd_mpeg_source_get_info (src);
    printf ("mpeg info\n");
  
    printf (" %d x %d (%f:1) @%f v%d\n", _info->shdr[0].hsize, _info->shdr[0].vsize,
	    _info->shdr[0].aratio, _info->shdr[0].frate, _info->version);
  }

  vcd_mpeg_source_destroy (src, true);

  return 0;
}