1 /*
2  *  Copyright (c) 2014 The WebM project authors. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 #ifndef VP9_DECODER_VP9_DTHREAD_H_
12 #define VP9_DECODER_VP9_DTHREAD_H_
13 
14 #include "./vpx_config.h"
15 #include "vpx_util/vpx_thread.h"
16 #include "vpx/internal/vpx_codec_internal.h"
17 
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21 
22 struct VP9Common;
23 struct VP9Decoder;
24 
25 // WorkerData for the FrameWorker thread. It contains all the information of
26 // the worker and decode structures for decoding a frame.
27 typedef struct FrameWorkerData {
28   struct VP9Decoder *pbi;
29   const uint8_t *data;
30   const uint8_t *data_end;
31   size_t data_size;
32   void *user_priv;
33   int result;
34   int worker_id;
35   int received_frame;
36 
37   // scratch_buffer is used in frame parallel mode only.
38   // It is used to make a copy of the compressed data.
39   uint8_t *scratch_buffer;
40   size_t scratch_buffer_size;
41 
42 #if CONFIG_MULTITHREAD
43   pthread_mutex_t stats_mutex;
44   pthread_cond_t stats_cond;
45 #endif
46 
47   int frame_context_ready;  // Current frame's context is ready to read.
48   int frame_decoded;        // Finished decoding current frame.
49 } FrameWorkerData;
50 
51 void vp9_frameworker_lock_stats(VPxWorker *const worker);
52 void vp9_frameworker_unlock_stats(VPxWorker *const worker);
53 void vp9_frameworker_signal_stats(VPxWorker *const worker);
54 
55 // Wait until ref_buf has been decoded to row in real pixel unit.
56 // Note: worker may already finish decoding ref_buf and release it in order to
57 // start decoding next frame. So need to check whether worker is still decoding
58 // ref_buf.
59 void vp9_frameworker_wait(VPxWorker *const worker, RefCntBuffer *const ref_buf,
60                           int row);
61 
62 // FrameWorker broadcasts its decoding progress so other workers that are
63 // waiting on it can resume decoding.
64 void vp9_frameworker_broadcast(RefCntBuffer *const buf, int row);
65 
66 // Copy necessary decoding context from src worker to dst worker.
67 void vp9_frameworker_copy_context(VPxWorker *const dst_worker,
68                                   VPxWorker *const src_worker);
69 
70 #ifdef __cplusplus
71 }  // extern "C"
72 #endif
73 
74 #endif  // VP9_DECODER_VP9_DTHREAD_H_
75