-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[media] Support decode-to-texture mode
Bring up decode-to-texture mode on Chrobalt. b/375070492
- Loading branch information
Showing
5 changed files
with
107 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
// Copyright 2018 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 MEDIA_STARBOARD_DECODE_TARGET_PROVIDER_H_ | ||
#define MEDIA_STARBOARD_DECODE_TARGET_PROVIDER_H_ | ||
|
||
#include "base/functional/callback.h" | ||
#include "base/memory/ref_counted.h" | ||
#include "base/synchronization/lock.h" | ||
#include "base/time/time.h" | ||
#include "starboard/decode_target.h" | ||
|
||
namespace media { | ||
|
||
// The DecodeTargetProvider manages the backlog for video frames. It has the | ||
// following functionalities: | ||
// 1. It caches the video frames ready to be displayed. | ||
// 2. It decides which frame to be displayed at the current time. | ||
// 3. It removes frames that will no longer be displayed. | ||
class DecodeTargetProvider | ||
: public base::RefCountedThreadSafe<DecodeTargetProvider> { | ||
public: | ||
enum OutputMode { | ||
kOutputModePunchOut, | ||
kOutputModeDecodeToTexture, | ||
kOutputModeInvalid, | ||
}; | ||
|
||
DecodeTargetProvider() : output_mode_(kOutputModeInvalid) {} | ||
|
||
DecodeTargetProvider(const DecodeTargetProvider&) = delete; | ||
DecodeTargetProvider& operator=(const DecodeTargetProvider&) = delete; | ||
|
||
using GetCurrentSbDecodeTargetFunction = | ||
base::RepeatingCallback<SbDecodeTarget()>; | ||
|
||
void SetOutputMode(OutputMode output_mode) { | ||
base::AutoLock auto_lock(lock_); | ||
output_mode_ = output_mode; | ||
} | ||
|
||
DecodeTargetProvider::OutputMode GetOutputMode() const { | ||
base::AutoLock auto_lock(lock_); | ||
return output_mode_; | ||
} | ||
|
||
// For Starboard platforms that have a decode-to-texture player, we enable | ||
// this DecodeTargetProvider to act as a bridge for Cobalt code to query | ||
// for the current SbDecodeTarget. In effect, we bypass all of | ||
// DecodeTargetProvider's logic in this case, instead relying on the | ||
// Starboard implementation to provide us with the current video frame when | ||
// needed. | ||
void SetGetCurrentSbDecodeTargetFunction( | ||
GetCurrentSbDecodeTargetFunction function) { | ||
base::AutoLock auto_lock(lock_); | ||
get_current_sb_decode_target_function_ = function; | ||
} | ||
|
||
void ResetGetCurrentSbDecodeTargetFunction() { | ||
base::AutoLock auto_lock(lock_); | ||
get_current_sb_decode_target_function_.Reset(); | ||
} | ||
|
||
SbDecodeTarget GetCurrentSbDecodeTarget() const { | ||
base::AutoLock auto_lock(lock_); | ||
if (get_current_sb_decode_target_function_.is_null()) { | ||
return kSbDecodeTargetInvalid; | ||
} else { | ||
return get_current_sb_decode_target_function_.Run(); | ||
} | ||
} | ||
|
||
private: | ||
mutable base::Lock lock_; | ||
|
||
OutputMode output_mode_; | ||
GetCurrentSbDecodeTargetFunction get_current_sb_decode_target_function_; | ||
}; | ||
|
||
} // namespace media | ||
|
||
#endif // MEDIA_STARBOARD_DECODE_TARGET_PROVIDER_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters