~ubuntu-branches/ubuntu/hoary/kdemultimedia/hoary

« back to all changes in this revision

Viewing changes to mpeglib/lib/mpegplay/gop.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Martin Schulze
  • Date: 2003-01-22 15:00:51 UTC
  • Revision ID: james.westby@ubuntu.com-20030122150051-uihwkdoxf15mi1tn
Tags: upstream-2.2.2
ImportĀ upstreamĀ versionĀ 2.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  parse/stores GOP (group of picture) information from a mpegVideoStream
 
3
  Copyright (C) 2000  Martin Vogt
 
4
 
 
5
  This program is free software; you can redistribute it and/or modify
 
6
  it under the terms of the GNU Library General Public License as published by
 
7
  the Free Software Foundation.
 
8
 
 
9
  For more information look at the file COPYRIGHT in this package
 
10
 
 
11
 */
 
12
 
 
13
 
 
14
#include "gop.h"
 
15
 
 
16
 
 
17
GOP::GOP() {
 
18
  drop_flag=false;
 
19
  tc_hours=0;
 
20
  tc_minutes=0;
 
21
  tc_seconds=0;
 
22
  tc_pictures=0;
 
23
  closed_gop=false;
 
24
  broken_link=false;
 
25
 
 
26
  mpegExtension=new MpegExtension();
 
27
 
 
28
}
 
29
 
 
30
 
 
31
GOP::~GOP() {
 
32
  delete mpegExtension;
 
33
}
 
34
 
 
35
 
 
36
/*
 
37
 *--------------------------------------------------------------
 
38
 *
 
39
 * ParseGOP --
 
40
 *
 
41
 *      Parses of group of pictures header from bit stream
 
42
 *      associated with vid_stream.
 
43
 *
 
44
 * Results:
 
45
 *      Values in gop header placed into video stream structure.
 
46
 *
 
47
 * Side effects:
 
48
 *      Bit stream irreversibly parsed.
 
49
 *
 
50
 *--------------------------------------------------------------
 
51
 */
 
52
int GOP::processGOP(MpegVideoStream* mpegVideoStream) {
 
53
  unsigned int data;
 
54
 
 
55
  /* Flush group of pictures start code. */
 
56
 
 
57
  mpegVideoStream->flushBits(32);
 
58
 
 
59
  /* Parse off drop frame flag. */
 
60
 
 
61
  data=mpegVideoStream->getBits(1);
 
62
 
 
63
  if (data) {
 
64
    drop_flag = true;
 
65
  } else
 
66
    drop_flag = false;
 
67
 
 
68
  /* Parse off hour component of time code. */
 
69
 
 
70
  tc_hours=mpegVideoStream->getBits(5);
 
71
 
 
72
  /* Parse off minute component of time code. */
 
73
 
 
74
  tc_minutes=mpegVideoStream->getBits(6);
 
75
 
 
76
 
 
77
  /* Flush marker bit. */
 
78
 
 
79
  mpegVideoStream->flushBits(1);
 
80
 
 
81
  /* Parse off second component of time code. */
 
82
 
 
83
  tc_seconds=mpegVideoStream->getBits(6);
 
84
  
 
85
  /* Parse off picture count component of time code. */
 
86
 
 
87
  tc_pictures=mpegVideoStream->getBits(6);
 
88
 
 
89
  /* Parse off closed gop and broken link flags. */
 
90
  data=mpegVideoStream->getBits(2);
 
91
  if (data > 1) {
 
92
    closed_gop = true;
 
93
    if (data > 2) {
 
94
      broken_link = true;
 
95
    } else
 
96
      broken_link = false;
 
97
  } else {
 
98
    closed_gop = false;
 
99
    if (data) {
 
100
      broken_link = true;
 
101
    } else
 
102
      broken_link = false;
 
103
  }
 
104
 
 
105
 
 
106
  /*
 
107
   * If next start code is extension/user start code, 
 
108
   * parse off extension data.
 
109
   */
 
110
 
 
111
  mpegExtension->processExtensionData(mpegVideoStream);
 
112
 
 
113
  return true; 
 
114
}
 
115
 
 
116
  
 
117
  
 
118
int GOP::substract(GOP* minus,GOP* dest) {
 
119
  int hours;
 
120
  int minutes;
 
121
  int seconds;
 
122
  hours=getHour()-minus->getHour();
 
123
  minutes=getMinutes()-minus->getMinutes();
 
124
  seconds=getSeconds()-minus->getSeconds();
 
125
 
 
126
  if (seconds < 0) {
 
127
    seconds+=60;
 
128
    minutes--;
 
129
  }
 
130
  if (minutes < 0) {
 
131
    minutes+=60;
 
132
    hours--;
 
133
  }
 
134
  dest->tc_hours=hours;
 
135
  dest->tc_minutes=minutes;
 
136
  dest->tc_seconds=seconds;
 
137
  if (hours < 0) {
 
138
    return false;
 
139
  }
 
140
  return true;
 
141
}
 
142
 
 
143
 
 
144
void GOP::copyTo(GOP* dest) {
 
145
  dest->tc_hours=getHour();
 
146
  dest->tc_minutes=getMinutes();
 
147
  dest->tc_seconds=getSeconds();
 
148
  dest->drop_flag=getDropFlag();
 
149
  dest->tc_pictures=getPictures();
 
150
  dest->closed_gop=getClosedGOP();
 
151
  dest->broken_link=getBrokenLink();
 
152
 
 
153
  // currently do not copy ext/user data FIX ME
 
154
}
 
155
 
 
156
 
 
157
void GOP::print(const char* description) {
 
158
  cout << "GOP [START]:"<<description<<endl;
 
159
  cout << "tc_hours:"<<getHour()<<endl;
 
160
  cout << "tc_minutes:"<<getMinutes()<<endl;
 
161
  cout << "tc_seconds:"<<getSeconds()<<endl;
 
162
  cout << "drop_flag:"<<getDropFlag()<<endl;
 
163
  cout << "tc_pictures:"<<getPictures()<<endl;
 
164
  cout << "closed_gop:"<<getClosedGOP()<<endl;
 
165
  cout << "broken_link:"<<getBrokenLink()<<endl;
 
166
  cout << "GOP [END]"<<endl;
 
167
}