chromium/third_party/libgav1/src/src/threading_strategy.h

/*
 * Copyright 2019 The libgav1 Authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef LIBGAV1_SRC_THREADING_STRATEGY_H_
#define LIBGAV1_SRC_THREADING_STRATEGY_H_

#include <memory>

#include "src/obu_parser.h"
#include "src/utils/compiler_attributes.h"
#include "src/utils/threadpool.h"

namespace libgav1 {

class FrameScratchBufferPool;

// This class allocates and manages the worker threads among thread pools used
// for multi-threaded decoding.
class ThreadingStrategy {};

// Initializes the |frame_thread_pool| and the necessary worker threadpools (the
// threading_strategy objects in each of the frame scratch buffer in
// |frame_scratch_buffer_pool|) as follows:
//  * frame_threads = ComputeFrameThreadCount();
//  * For more details on how frame_threads is computed, see the function
//    comment in ComputeFrameThreadCount().
//  * |frame_thread_pool| is created with |frame_threads| threads.
//  * divide the remaining number of threads into each frame thread and
//    initialize a frame_scratch_buffer.threading_strategy for each frame
//    thread.
//  When this function is called, |frame_scratch_buffer_pool| must be empty. If
//  this function returns true, it means the initialization was successful and
//  one of the following is true:
//    * |frame_thread_pool| has been successfully initialized and
//      |frame_scratch_buffer_pool| has been successfully populated with
//      |frame_threads| buffers to be used by each frame thread. The total
//      number of threads that this function creates will always be equal to
//      |thread_count|.
//    * |frame_thread_pool| is nullptr. |frame_scratch_buffer_pool| is not
//      modified. This means that frame threading will not be used and the
//      decoder will continue to operate normally in non frame parallel mode.
LIBGAV1_MUST_USE_RESULT bool InitializeThreadPoolsForFrameParallel(
    int thread_count, int tile_count, int tile_columns,
    std::unique_ptr<ThreadPool>* frame_thread_pool,
    FrameScratchBufferPool* frame_scratch_buffer_pool);

}  // namespace libgav1

#endif  // LIBGAV1_SRC_THREADING_STRATEGY_H_