projector_metadata_model.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. // Copyright 2021 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 ASH_PROJECTOR_PROJECTOR_METADATA_MODEL_H_
  5. #define ASH_PROJECTOR_PROJECTOR_METADATA_MODEL_H_
  6. #include <memory>
  7. #include <string>
  8. #include <vector>
  9. #include "ash/ash_export.h"
  10. #include "base/time/time.h"
  11. #include "media/mojo/mojom/speech_recognition.mojom.h"
  12. namespace base {
  13. class Value;
  14. } // namespace base
  15. namespace ash {
  16. // Base class to describe a metadata item.
  17. class MetadataItem {
  18. public:
  19. MetadataItem(const base::TimeDelta start_time,
  20. const base::TimeDelta end_time,
  21. const std::string& text);
  22. MetadataItem(const MetadataItem&) = delete;
  23. MetadataItem& operator=(const MetadataItem&) = delete;
  24. virtual ~MetadataItem();
  25. base::TimeDelta& start_time() { return start_time_; }
  26. base::TimeDelta& end_time() { return end_time_; }
  27. // Return the serialized metadata item. This is used for storage.
  28. virtual base::Value ToJson() = 0;
  29. protected:
  30. // The start time of the metadata item from the start of the recording
  31. // session.
  32. base::TimeDelta start_time_;
  33. // The end time of the metadata item from the start of the recording session.
  34. base::TimeDelta end_time_;
  35. // Text data of the metadata item.
  36. std::string text_;
  37. };
  38. // Class to describe a key idea.
  39. class ASH_EXPORT ProjectorKeyIdea : public MetadataItem {
  40. public:
  41. ProjectorKeyIdea(const base::TimeDelta start_time,
  42. const base::TimeDelta end_time,
  43. const std::string& text = std::string());
  44. ProjectorKeyIdea(const ProjectorKeyIdea&) = delete;
  45. ProjectorKeyIdea& operator=(const ProjectorKeyIdea&) = delete;
  46. ~ProjectorKeyIdea() override;
  47. base::Value ToJson() override;
  48. };
  49. // Class to describe a transcription.
  50. class ASH_EXPORT ProjectorTranscript : public MetadataItem {
  51. public:
  52. ProjectorTranscript(
  53. const base::TimeDelta start_time,
  54. const base::TimeDelta end_time,
  55. const std::string& text,
  56. const std::vector<media::HypothesisParts>& hypothesis_parts);
  57. ProjectorTranscript(const ProjectorTranscript&) = delete;
  58. ProjectorTranscript& operator=(const ProjectorTranscript&) = delete;
  59. ~ProjectorTranscript() override;
  60. base::Value ToJson() override;
  61. private:
  62. std::vector<media::HypothesisParts> hypothesis_parts_;
  63. };
  64. // Class to describe a projector metadata of a screencast session, including
  65. // name, transcriptions, key_ideas, etc
  66. class ASH_EXPORT ProjectorMetadata {
  67. public:
  68. ProjectorMetadata();
  69. ProjectorMetadata(const ProjectorMetadata&) = delete;
  70. ProjectorMetadata& operator=(const ProjectorMetadata&) = delete;
  71. ~ProjectorMetadata();
  72. // Sets the language of the transcript.
  73. void SetCaptionLanguage(const std::string& language);
  74. // Adds the transcript to the metadata.
  75. void AddTranscript(std::unique_ptr<ProjectorTranscript> transcript);
  76. // Marks a beginning of a key idea. The timing info of the next transcript
  77. // will be used as the timing of the key idea.
  78. void MarkKeyIdea();
  79. // Serializes the metadata for storage.
  80. std::string Serialize();
  81. // Returns the number of transcripts.
  82. size_t GetTranscriptsCount() const { return transcripts_.size(); }
  83. private:
  84. base::Value ToJson();
  85. std::vector<std::unique_ptr<ProjectorTranscript>> transcripts_;
  86. std::vector<std::unique_ptr<ProjectorKeyIdea>> key_ideas_;
  87. std::string caption_language_;
  88. // True if user mark the transcript as a key idea. It will be reset to false
  89. // when the final recognition result is received and recorded as a key idea.
  90. bool should_mark_key_idea_ = false;
  91. };
  92. } // namespace ash
  93. #endif // ASH_PROJECTOR_PROJECTOR_METADATA_MODEL_H_