learning_helper.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Copyright 2018 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef MEDIA_CAPABILITIES_LEARNING_HELPER_H_
  5. #define MEDIA_CAPABILITIES_LEARNING_HELPER_H_
  6. #include <memory>
  7. #include "base/threading/sequence_bound.h"
  8. #include "media/base/media_export.h"
  9. #include "media/capabilities/video_decode_stats_db.h"
  10. #include "media/learning/impl/feature_provider.h"
  11. #include "media/learning/impl/learning_session_impl.h"
  12. namespace media {
  13. // Helper class to allow MediaCapabilities to log training examples to a
  14. // media::learning LearningTask.
  15. class MEDIA_EXPORT LearningHelper {
  16. public:
  17. // |feature_factory| lets us register FeatureProviders with those
  18. // LearningTasks that include standard features.
  19. LearningHelper(learning::FeatureProviderFactoryCB feature_factory);
  20. ~LearningHelper();
  21. // |origin| is sent in separately since it's somewhat hacky. This should be
  22. // provided by the FeatureProvider, but the way LearningHelper is used, it
  23. // doesn't have access to the origin. Per-frame LearningTaskControllers will
  24. // be able to do this much more easily.
  25. void AppendStats(const VideoDecodeStatsDB::VideoDescKey& video_key,
  26. learning::FeatureValue origin,
  27. const VideoDecodeStatsDB::DecodeStatsEntry& new_stats);
  28. private:
  29. // Convenience function to begin and complete an observation.
  30. void AddExample(learning::LearningTaskController* controller,
  31. const learning::LabelledExample& example);
  32. // Learning session for our profile. Normally, we'd not have one of these
  33. // directly, but would instead get one that's connected to a browser profile.
  34. // For now, however, we just instantiate one and assume that we'll be
  35. // destroyed when the profile changes / history is cleared.
  36. std::unique_ptr<learning::LearningSessionImpl> learning_session_;
  37. // Controllers for each task.
  38. std::unique_ptr<learning::LearningTaskController>
  39. base_unweighted_table_controller_;
  40. std::unique_ptr<learning::LearningTaskController>
  41. base_unweighted_tree_controller_;
  42. std::unique_ptr<learning::LearningTaskController>
  43. base_unweighted_tree_200_controller_;
  44. std::unique_ptr<learning::LearningTaskController>
  45. enhanced_unweighted_tree_200_controller_;
  46. };
  47. } // namespace media
  48. #endif // MEDIA_CAPABILITIES_LEARNING_HELPER_H_