Skip to content

Commit 4551567

Browse files
update player
1 parent a09a3d0 commit 4551567

File tree

2 files changed

+52
-18
lines changed

2 files changed

+52
-18
lines changed

app/avplay/main.cpp

Lines changed: 51 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@ bool showGreenChannel = false;
7171
bool showBlueChannel = false;
7272
bool showAlphaChannel = false;
7373

74+
bool play = false;
75+
76+
avtranscoder::InputStreamVideo* pInputStreamVideo = NULL;
77+
avtranscoder::ColorTransform ct;
78+
avtranscoder::Image* pSourceImage = NULL;
79+
avtranscoder::Image* pImageToDisplay = NULL;
80+
81+
7482
void reshape(int width, int height)
7583
{
7684
float w, h, xPos, yPos;
@@ -132,6 +140,13 @@ void loadNewTexture( const char* data, GLint internalFormat, size_t width, size_
132140
}
133141

134142

143+
void readAndLoadNextFrame()
144+
{
145+
pInputStreamVideo->readNextFrame( *pSourceImage );
146+
ct.convert( *pSourceImage, *pImageToDisplay );
147+
loadNewTexture( (const char*)( pImageToDisplay->getPtr() ), img.component, img.width, img.height, img.format, img.type );
148+
}
149+
135150
void reloadTexture( )
136151
{
137152
loadNewTexture( img );
@@ -269,6 +284,8 @@ void display()
269284

270285
void idle()
271286
{
287+
if( play )
288+
readAndLoadNextFrame();
272289
}
273290

274291
void displayInformations()
@@ -294,6 +311,7 @@ void displayHelp()
294311
static const std::string kViewerHelp =
295312
"Av Player Viewer Help\n" \
296313
"i : information about image (dimensions, bit depth, channels)\n"\
314+
"m : full metadatas of media\n"\
297315
"z : zoom view to 1:1\n"\
298316
"h, F1 : print help\n" \
299317
"SHIFT + V : flip\n" \
@@ -356,9 +374,11 @@ void keyboard(unsigned char k, int x, int y)
356374
{
357375
case '\r':
358376
glutDestroyWindow(windowID);
377+
windowID = 0;
359378
break;
360379
case 27: // ESCAPE key
361380
glutDestroyWindow(windowID);
381+
windowID = 0;
362382
break;
363383
case 'i':
364384
displayInformations();
@@ -368,15 +388,15 @@ void keyboard(unsigned char k, int x, int y)
368388
currentZoom = 1.0;
369389
x1Quad = -1.0;
370390
x2Quad = 1.0;
371-
y1Quad = -1.0;
372-
y2Quad = 1.0;
391+
y1Quad = 1.0;
392+
y2Quad = -1.0;
373393
glutPostRedisplay();
374394
break;
375395
case 'h':
376396
displayHelp();
377397
break;
378398
case SPACEBAR:
379-
glutDestroyWindow(windowID);
399+
play = !play;
380400
break;
381401

382402
case 'r':
@@ -425,6 +445,7 @@ void specialKeyboard( int k, int x, int y)
425445
break;
426446
case GLUT_KEY_RIGHT:
427447
// cursor move
448+
readAndLoadNextFrame();
428449
break;
429450
case GLUT_KEY_F1:
430451
displayHelp();
@@ -547,8 +568,8 @@ void openGLWindow( const size_t& width, const size_t& height )
547568

548569
x1Quad = -1.0;
549570
x2Quad = 1.0;
550-
y1Quad = -1.0;
551-
y2Quad = 1.0;
571+
y1Quad = 1.0;
572+
y2Quad = -1.0;
552573

553574
glutDisplayFunc (display);
554575

@@ -568,29 +589,42 @@ int main( int argc, char** argv )
568589
avtranscoder::InputFile inputFile( argv[1] );
569590

570591
inputFile.analyse();
571-
size_t width = inputFile.getProperties().videoStreams.at(0).width;
572-
size_t height = inputFile.getProperties().videoStreams.at(0).height;
573-
size_t components = 3;
574-
GLenum format = GL_RGB;
575-
GLenum type = GL_UNSIGNED_BYTE;
592+
img.width = inputFile.getProperties().videoStreams.at(0).width;
593+
img.height = inputFile.getProperties().videoStreams.at(0).height;
594+
img.component = 3;
595+
img.format = GL_RGB;
596+
img.type = GL_UNSIGNED_BYTE;
576597
//GLenum type = GL_UNSIGNED_SHORT;
577598

578599
avtranscoder::InputStreamVideo inputStreamVideo( inputFile.getStream( 0 ) );
600+
pInputStreamVideo = &inputStreamVideo;
579601
avtranscoder::Image sourceImage( inputFile.getStream( 0 ).getVideoDesc().getImageDesc() );
580602

581-
avtranscoder::Image imageToDisplay( sourceImage );
603+
avtranscoder::Pixel pixel;
604+
pixel.setBitsPerPixel( img.component * 8 );
605+
pixel.setComponents( img.component );
606+
pixel.setColorComponents( avtranscoder::eComponentRgb );
607+
pixel.setSubsampling( avtranscoder::eSubsamplingNone );
608+
pixel.setAlpha( false );
609+
pixel.setPlanar( false );
610+
611+
avtranscoder::ImageDesc imageDescToDisplay;
582612

583-
inputStreamVideo.readNextFrame( sourceImage );
613+
imageDescToDisplay.setWidth ( sourceImage.desc().getWidth() );
614+
imageDescToDisplay.setHeight( sourceImage.desc().getHeight() );
615+
imageDescToDisplay.setDar ( sourceImage.desc().getDar() );
616+
imageDescToDisplay.setPixel ( pixel.findPixel() );
584617

585-
avtranscoder::ColorTransform ct;
586-
ct.convert( sourceImage, imageToDisplay );
618+
avtranscoder::Image imageToDisplay( imageDescToDisplay );
587619

588-
openGLWindow( width, height );
620+
pSourceImage = &sourceImage;
621+
pImageToDisplay = &imageToDisplay;
589622

623+
openGLWindow( img.width, img.height );
590624

591-
loadNewTexture( (const char*)( imageToDisplay.getPtr() ), components, width, height, format, type );
625+
readAndLoadNextFrame();
592626

593-
glutIdleFunc(idle);
627+
glutIdleFunc( idle );
594628
glutMainLoop();
595629

596630
std::cout << "avplay end ..." << std::endl;

src/AvTranscoder/InputStreamVideo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ InputStreamVideo::~InputStreamVideo()
6363
{
6464
if( m_codecContext != NULL )
6565
{
66-
avcodec_close( m_codecContext );
66+
//avcodec_close( m_codecContext );
6767
av_free( m_codecContext );
6868
m_codecContext = NULL;
6969
}

0 commit comments

Comments
 (0)