1 /*****************************************************************************
2  * Copyright (C) 2013 x265 project
3  *
4  * Authors: Peixuan Zhang <zhangpeixuancn@gmail.com>
5  *          Chunli Zhang <chunli@multicorewareinc.com>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111, USA.
20  *
21  * This program is also available under a commercial proprietary license.
22  * For more information, contact us at license @ x265.com.
23  *****************************************************************************/
24 
25 #ifndef X265_RECONPLAY_H
26 #define X265_RECONPLAY_H
27 
28 #include "x265.h"
29 #include "threading.h"
30 #include <cstdio>
31 
32 namespace X265_NS {
33 // private x265 namespace
34 
35 class ReconPlay : public Thread
36 {
37 public:
38 
39     ReconPlay(const char* commandLine, x265_param& param);
40 
41     virtual ~ReconPlay();
42 
43     bool writePicture(const x265_picture& pic);
44 
45     static bool pipeValid;
46 
47 protected:
48 
49     enum { RECON_BUF_SIZE = 40 };
50 
51     FILE*  outputPipe;     /* The output pipe for player */
52     size_t frameSize;      /* size of one frame in pixels */
53     bool   threadActive;   /* worker thread is active */
54     int    width;          /* width of frame */
55     int    height;         /* height of frame */
56     int    colorSpace;     /* color space of frame */
57 
58     int    poc[RECON_BUF_SIZE];
59     pixel* frameData[RECON_BUF_SIZE];
60 
61     /* Note that the class uses read and write counters to signal that reads and
62      * writes have occurred in the ring buffer, but writes into the buffer
63      * happen in decode order and the reader must check that the POC it next
64      * needs to send to the pipe is in fact present.  The counters are used to
65      * prevent the writer from getting too far ahead of the reader */
66     ThreadSafeInteger readCount;
67     ThreadSafeInteger writeCount;
68 
69     void threadMain();
70     bool outputFrame();
71 };
72 }
73 
74 #endif // ifndef X265_RECONPLAY_H
75