// Copyright 2020 The Cobalt Authors. All Rights Reserved.
//
// 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 STARBOARD_SHARED_UWP_DECODER_UTILS_H_
#define STARBOARD_SHARED_UWP_DECODER_UTILS_H_

#include <d3d11_1.h>
#include <wrl/client.h>

#include <algorithm>

#include "starboard/media.h"
#include "starboard/time.h"

namespace starboard {
namespace shared {
namespace uwp {

Microsoft::WRL::ComPtr<ID3D11Device> GetDirectX11Device(void* display);

// This is a utility function for finding entries with the method timestamp()
// in containers. Useful in decoders for getting data from buffers keeped in
// input queues;
template <typename Container>
const auto FindByTimestamp(const Container& container, SbTime timestamp) {
  return std::find_if(container.begin(), container.end(),
                      [=](const typename Container::value_type& value) {
                        return value->timestamp() == timestamp;
                      });
}

// This is a utility function for removing entries with the method timestamp()
// from containers. Useful in decoders for cleaning up input and output queues
// from expired buffers.
template <typename Container>
void RemoveByTimestamp(Container* container, SbTime timestamp) {
  auto to_remove =
      std::find_if(container->begin(), container->end(),
                   [=](const typename Container::value_type& value) {
                     return value->timestamp() == timestamp;
                   });
  if (to_remove != container->end()) {
    container->erase(to_remove);
  }
}

void UpdateHdrColorMetadataToCurrentDisplay(
    const SbMediaColorMetadata& color_metadata);

}  // namespace uwp
}  // namespace shared
}  // namespace starboard

#endif  // STARBOARD_SHARED_UWP_DECODER_UTILS_H_
