~vanvugt/ubuntu/oneiric/mediatomb/fix-770964-784431

« back to all changes in this revision

Viewing changes to src/mpegdemux/mpeg_remux.c

  • Committer: Bazaar Package Importer
  • Author(s): Andres Mejia
  • Date: 2009-04-22 21:39:19 UTC
  • mto: (4.2.1 sid)
  • mto: This revision was merged to the branch mainline in revision 9.
  • Revision ID: james.westby@ubuntu.com-20090422213919-52m015y6gcpv1m1g
Tags: upstream-0.12.0~svn2018
ImportĀ upstreamĀ versionĀ 0.12.0~svn2018

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*****************************************************************************
 
2
 * mpegdemux                                                                 *
 
3
 *****************************************************************************/
 
4
 
 
5
/*****************************************************************************
 
6
 * File name:     mpeg_remux.c                                               *
 
7
 * Created:       2003-02-02 by Hampa Hug <hampa@hampa.ch>                   *
 
8
 * Last modified: 2003-09-10 by Hampa Hug <hampa@hampa.ch>                   *
 
9
 * Copyright:     (C) 2003 by Hampa Hug <hampa@hampa.ch>                     *
 
10
 *****************************************************************************/
 
11
 
 
12
/*****************************************************************************
 
13
 * This program is free software. You can redistribute it and / or modify it *
 
14
 * under the terms of the GNU General Public License version 2 as  published *
 
15
 * by the Free Software Foundation.                                          *
 
16
 *                                                                           *
 
17
 * This program is distributed in the hope  that  it  will  be  useful,  but *
 
18
 * WITHOUT  ANY   WARRANTY,   without   even   the   implied   warranty   of *
 
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU  General *
 
20
 * Public License for more details.                                          *
 
21
 *****************************************************************************/
 
22
 
 
23
/* $Id: mpeg_remux.c 67 2004-01-02 18:20:15Z hampa $ */
 
24
 
 
25
// The code has been modified to use file descriptors instead of FILE streams.
 
26
// Only functionality needed in MediaTomb remains, all extra features are
 
27
// stripped out.
 
28
 
 
29
 
 
30
#ifdef HAVE_CONFIG_H
 
31
    #include "autoconfig.h"
 
32
#endif
 
33
 
 
34
#ifdef HAVE_LIBDVDNAV
 
35
 
 
36
#include <stdio.h>
 
37
#include <stdlib.h>
 
38
#include <string.h>
 
39
 
 
40
#include "buffer.h"
 
41
#include "mpeg_parse.h"
 
42
#include "mpeg_remux.h"
 
43
#include "mpegdemux_internal.h"
 
44
 
 
45
 
 
46
static mpeg_buffer_t shdr = { NULL, 0, 0 };
 
47
static mpeg_buffer_t pack = { NULL, 0, 0 };
 
48
static mpeg_buffer_t packet = { NULL, 0, 0 };
 
49
 
 
50
static
 
51
int mpeg_remux_system_header (mpeg_demux_t *mpeg)
 
52
{
 
53
  if (mpeg_buf_write_clear (&pack, mpeg->ext)) {
 
54
    return (1);
 
55
  }
 
56
 
 
57
  if (mpeg_buf_read (&shdr, mpeg, mpeg->shdr.size)) {
 
58
    return (1);
 
59
  }
 
60
 
 
61
  if (mpeg_buf_write_clear (&shdr, mpeg->ext)) {
 
62
    return (1);
 
63
  }
 
64
 
 
65
  return (0);
 
66
}
 
67
 
 
68
static
 
69
int mpeg_remux_packet (mpeg_demux_t *mpeg)
 
70
{
 
71
  int      r;
 
72
  unsigned sid, ssid;
 
73
 
 
74
  sid = mpeg->packet.sid;
 
75
  ssid = mpeg->packet.ssid;
 
76
 
 
77
  if (mpeg_stream_excl (sid, ssid)) {
 
78
    return (0);
 
79
  }
 
80
 
 
81
  r = 0;
 
82
 
 
83
  if (mpeg_buf_read (&packet, mpeg, mpeg->packet.size)) {
 
84
    fprintf(stderr, "remux: incomplete packet (sid=%02x size=%u/%u)\n",
 
85
      sid, packet.cnt, mpeg->packet.size
 
86
    );
 
87
 
 
88
    if (par_drop) {
 
89
      mpeg_buf_clear (&packet);
 
90
      return (1);
 
91
    }
 
92
 
 
93
    r = 1;
 
94
  }
 
95
 
 
96
  if (mpeg_buf_write_clear (&pack, mpeg->ext)) {
 
97
    return (1);
 
98
  }
 
99
 
 
100
  if (mpeg_buf_write_clear (&packet, mpeg->ext)) {
 
101
    return (1);
 
102
  }
 
103
 
 
104
  return (r);
 
105
}
 
106
 
 
107
static
 
108
int mpeg_remux_pack (mpeg_demux_t *mpeg)
 
109
{
 
110
  if (mpeg_buf_read (&pack, mpeg, mpeg->pack.size)) {
 
111
    return (1);
 
112
  }
 
113
 
 
114
  if (par_empty_pack) {
 
115
    if (mpeg_buf_write_clear (&pack, mpeg->ext)) {
 
116
      return (1);
 
117
    }
 
118
  }
 
119
 
 
120
  return (0);
 
121
}
 
122
 
 
123
static
 
124
int mpeg_remux_end (mpeg_demux_t *mpeg)
 
125
{
 
126
  if (mpeg_copy (mpeg, mpeg->ext, 4)) {
 
127
    return (1);
 
128
  }
 
129
 
 
130
  return (0);
 
131
}
 
132
 
 
133
int mpeg_remux (int inp, int out)
 
134
{
 
135
  int          r;
 
136
  mpeg_demux_t *mpeg;
 
137
 
 
138
  mpeg = mpegd_open_fd (NULL, inp, 0);
 
139
  if (mpeg == NULL) {
 
140
    return (1);
 
141
  }
 
142
 
 
143
  mpeg->ext = out;
 
144
  mpeg->mpeg_system_header = &mpeg_remux_system_header;
 
145
  mpeg->mpeg_pack = &mpeg_remux_pack;
 
146
  mpeg->mpeg_packet = &mpeg_remux_packet;
 
147
  mpeg->mpeg_packet_check = &mpeg_packet_check;
 
148
  mpeg->mpeg_end = &mpeg_remux_end;
 
149
 
 
150
  mpeg_buf_init (&shdr);
 
151
  mpeg_buf_init (&pack);
 
152
  mpeg_buf_init (&packet);
 
153
 
 
154
  r = mpegd_parse (mpeg);
 
155
 
 
156
  mpegd_close (mpeg);
 
157
 
 
158
  mpeg_buf_free (&shdr);
 
159
  mpeg_buf_free (&pack);
 
160
  mpeg_buf_free (&packet);
 
161
 
 
162
  return (r);
 
163
}
 
164
 
 
165
#endif//HAVE_LIBDVDNAV