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

« back to all changes in this revision

Viewing changes to mpeglib/lib/decoder/mpegPlugin.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
  mpeg player plugin
 
3
  Copyright (C) 1999  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 "mpegPlugin.h"
 
15
 
 
16
#include "../mpegplay/mpegVideoStream.h"
 
17
#include "../mpegplay/proto.h"
 
18
#include "../mpegplay/mpegVideoHeader.h"
 
19
 
 
20
 
 
21
 
 
22
MpegPlugin::MpegPlugin() {
 
23
  init();
 
24
}
 
25
 
 
26
 
 
27
MpegPlugin::~MpegPlugin() {
 
28
}
 
29
 
 
30
 
 
31
void MpegPlugin::init() {
 
32
  lCalcLength=false;
 
33
  mpegVideoHeader=NULL;
 
34
  mpegVideoStream=NULL;
 
35
}
 
36
 
 
37
 
 
38
void MpegPlugin::decoder_loop() {
 
39
 
 
40
 
 
41
  VideoDecoder* video=NULL;
 
42
  if (input == NULL) {
 
43
    cout << "MpegPlugin::decoder_loop input is NULL"<<endl;
 
44
    exit(0);
 
45
  }
 
46
  if (output == NULL) {
 
47
    cout << "MpegPlugin::decoder_loop output is NULL"<<endl;
 
48
    exit(0);
 
49
  }
 
50
 
 
51
  mpegVideoHeader=new MpegVideoHeader();
 
52
  mpegVideoStream=new MpegVideoStream(input);
 
53
 
 
54
  PictureArray* pictureArray;
 
55
  YUVPicture* pic;
 
56
  int skipMode=_SYNC_TO_NONE;
 
57
  // decode loop
 
58
 
 
59
  while(runCheck()) {
 
60
    switch(streamState) {
 
61
    case _STREAM_STATE_FIRST_INIT :
 
62
      if (mpegVideoStream->firstInitialize(mpegVideoHeader)==false) {
 
63
 
 
64
      } else {
 
65
        pluginInfo->setLength(getSongLength());
 
66
        
 
67
        // now create pictureArray from the sequence
 
68
        int width=mpegVideoHeader->getMB_Width()*16;
 
69
        int height=mpegVideoHeader->getMB_Height()*16;
 
70
 
 
71
        output->openWindow(width,height,(char*)"kmpg");
 
72
        video=new VideoDecoder(mpegVideoStream,mpegVideoHeader);
 
73
        setStreamState(_STREAM_STATE_INIT);
 
74
      }
 
75
      break;
 
76
    case _STREAM_STATE_INIT :
 
77
      //      cout << "mpeg _STREAM_STATE_INI"<<endl;
 
78
      if (skipMode==_SYNC_TO_GOP) {
 
79
        if (mpegVideoStream->nextGOP()==false) {
 
80
          continue;
 
81
        }
 
82
        video->resyncToI_Frame();
 
83
      }
 
84
      if (skipMode==_SYNC_TO_PIC) {
 
85
        if (mpegVideoStream->nextPIC()==false) {
 
86
          continue;
 
87
        }
 
88
      }
 
89
      skipMode=_SYNC_TO_NONE;
 
90
      setStreamState(_STREAM_STATE_PLAY);
 
91
      break;
 
92
    case _STREAM_STATE_PLAY :
 
93
      pictureArray=output->lockPictureArray();
 
94
      skipMode=video->mpegVidRsrc(pictureArray);
 
95
 
 
96
      if (skipMode != _SYNC_TO_NONE) {
 
97
        setStreamState(_STREAM_STATE_INIT);
 
98
      }
 
99
      pic=pictureArray->getYUVPictureCallback();
 
100
      if (pic == NULL) {
 
101
        // nothin to display
 
102
        break;
 
103
      }
 
104
 
 
105
      output->unlockPictureArray(pictureArray);
 
106
      pictureArray->setYUVPictureCallback(NULL);
 
107
      break;
 
108
    case _STREAM_STATE_WAIT_FOR_END:
 
109
      // exit while loop
 
110
      lDecoderLoop=false;
 
111
      break;
 
112
    default:
 
113
      cout << "unknown stream state:"<<streamState<<endl;
 
114
    }
 
115
  }
 
116
 
 
117
  output->flushWindow();
 
118
  // copy sequence back if needed
 
119
  if (video != NULL) {
 
120
    delete video;
 
121
  }
 
122
  delete mpegVideoStream;
 
123
  delete mpegVideoHeader;
 
124
  mpegVideoStream=NULL;
 
125
  mpegVideoHeader=NULL;
 
126
}
 
127
 
 
128
 
 
129
 
 
130
 
 
131
 
 
132
// here we can config our decoder with special flags
 
133
void MpegPlugin::config(const char* key,const char* value,void* user_data) {
 
134
  if (strcmp(key,"-c")==0) {
 
135
    lCalcLength=false;
 
136
  }
 
137
 
 
138
  if (strcmp(key,"decode")==0) {
 
139
    if (strcmp(value,"true")==0) {
 
140
      lDecode=true;
 
141
    } else {
 
142
      lDecode=false;
 
143
    }
 
144
  }    
 
145
  DecoderPlugin::config(key,value,user_data);
 
146
}
 
147
 
 
148
 
 
149
 
 
150
int MpegPlugin::getSongLength() {
 
151
  int back=0;
 
152
  return back;
 
153
}
 
154
 
 
155
 
 
156
 
 
157
 
 
158
 
 
159