1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61

media / muxers / mp4_muxer_context.h [blame]

// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef MEDIA_MUXERS_MP4_MUXER_CONTEXT_H_
#define MEDIA_MUXERS_MP4_MUXER_CONTEXT_H_

#include <map>
#include <memory>
#include <optional>

#include "base/sequence_checker.h"
#include "media/base/media_export.h"

namespace media {

class OutputPositionTracker;

// The class provides any additional data that isn't part of box.
// Usually, the data will be set in the middle of box data creation, but
// can be also set during writing box.
class MEDIA_EXPORT Mp4MuxerContext {
 public:
  explicit Mp4MuxerContext(
      std::unique_ptr<OutputPositionTracker> output_position_tracker);
  ~Mp4MuxerContext();
  Mp4MuxerContext(const Mp4MuxerContext&) = delete;
  Mp4MuxerContext& operator=(const Mp4MuxerContext&) = delete;

  // Per track data that will be provided by the client.
  struct Track {
    size_t index;
    uint32_t timescale;
  };

  // Track will be created and inserted to vector by the order of arrival
  // on Muxer so video or audio index could be different on new stream
  // collection (e.g. after putRequest).

  // It also needs to set the timescale for the video/audio track that will
  // be used to duration conversion.
  void SetVideoTrack(Track track);
  void SetAudioTrack(Track track);

  std::optional<Track> GetVideoTrack() const;
  std::optional<Track> GetAudioTrack() const;

  OutputPositionTracker& GetOutputPositionTracker() const;

 private:
  std::optional<Track> video_track_;
  std::optional<Track> audio_track_;

  std::unique_ptr<OutputPositionTracker> output_position_tracker_;

  SEQUENCE_CHECKER(sequence_checker_);
};

}  // namespace media

#endif  // MEDIA_MUXERS_MP4_MUXER_CONTEXT_H_