summaryrefslogtreecommitdiffstats
path: root/mpeglib/lib/yuv/yuvPlugin.cpp
blob: 94697aa829857a53244f4357cd96dd568c94a2c7 (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
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*
  raw yuv stream player
  Copyright (C) 2000  Martin Vogt

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU Library General Public License as published by
  the Free Software Foundation.

  For more information look at the file COPYRIGHT in this package

 */


#include "yuvPlugin.h"

#include <iostream>

using namespace std;


YUVPlugin::YUVPlugin() {
  init();
}


YUVPlugin::~YUVPlugin() {
}


void YUVPlugin::init() {
  lCalcLength=false;
  nWidth=0;
  nHeight=0;
  imageType=PICTURE_YUVMODE_CR_CB;
  picPerSec=1.0;
}


void YUVPlugin::decoder_loop() {



  cout << "YUVPlugin::decoder_loop() 1"<<endl;
  if (input == NULL) {
    cout << "YUVPlugin::decoder_loop input is NULL"<<endl;
    exit(0);
  }
  if (output == NULL) {
    cout << "YUVPlugin::decoder_loop output is NULL"<<endl;
    exit(0);
  }


  PictureArray* pictureArray;


  int bytes=nWidth*nHeight;

  if ( (imageType == PICTURE_YUVMODE_CR_CB) ||
       (imageType == PICTURE_YUVMODE_CB_CR) ) {
    bytes=bytes+bytes/2;
  }
  if ( (imageType == PICTURE_RGB) ||
       (imageType == PICTURE_RGB_FLIPPED) ) {
    bytes=bytes*4;
  }

  


  // decode loop
  while(runCheck()) {
    switch(streamState) {
    case _STREAM_STATE_FIRST_INIT :
      output->openWindow(nWidth,nHeight,(char*)"yuv Viewer");
      pictureArray=output->lockPictureArray();
      cout << "pictureArray->setImageType"<<endl;
      pictureArray->setImageType(imageType);
      
      setStreamState(_STREAM_STATE_INIT);
      break;
    case _STREAM_STATE_INIT :
      setStreamState(_STREAM_STATE_PLAY);
      break;
    case _STREAM_STATE_PLAY : {
      // we read from input raw yuv bytes 
      // and display them.
      pictureArray=output->lockPictureArray();
      // now we have the color info
      YUVPicture* pic=pictureArray->getPast();
      unsigned char* dest=pic->getImagePtr();
      input->read((char*)dest,bytes);
      pic->setPicturePerSecond(picPerSec);
      // now inform subsystem about the frame to display
      pictureArray->setYUVPictureCallback(pic);
      //  display it
      output->unlockPictureArray(pictureArray);

      pictureArray->setYUVPictureCallback(NULL);
      break;
    }
    case _STREAM_STATE_WAIT_FOR_END:
      // exit while loop
      lDecoderLoop=false;
      cout << "mpegplugin _STREAM_STATE_WAIT_FOR_END"<<endl;
      break;
    default:
      cout << "unknown stream state:"<<streamState<<endl;
    }
  }

  cout << "*********mpegPLugin exit"<<endl;

  output->flushWindow();
  // copy sequence back if needed

  cout << "delete mpegVideoStream"<<endl;

}





// here we can config our decoder with special flags
void YUVPlugin::config(const char* key,const char* value,void* user_data) {
  if (strcmp(key,"-c")==0) {
    lCalcLength=false;
  }

  if (strcmp(key,"height")==0) {
    nHeight=atoi(value);
  }    
  if (strcmp(key,"width")==0) {
    nWidth=atoi(value);
  }    
  if (strcmp(key,"imageType")==0) {
    imageType=atoi(value);
    cout << "imageType:"<<imageType<<endl;
  }      
  if (strcmp(key,"picPerSec")==0) {
    picPerSec=atoi(value);
  }
  DecoderPlugin::config(key,value,user_data);
}



int YUVPlugin::getSongLength() {
  int back=0;
  return back;
}