summaryrefslogtreecommitdiff
path: root/chromium/media/base/demuxer_memory_limit_cast_unittest.cc
blob: 41b68a20aedeeaed53b532feb8e7a883ab9b7c84 (plain)
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/optional.h"
#include "media/base/audio_decoder_config.h"
#include "media/base/demuxer.h"
#include "media/base/demuxer_memory_limit.h"
#include "media/base/media_util.h"
#include "media/base/video_decoder_config.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace media {

static const gfx::Size kCodedSize(320, 240);
static const gfx::Rect kVisibleRect(320, 240);
static const gfx::Size kNaturalSize(320, 240);

TEST(DemuxerMemoryLimitCastTest, GetDemuxerStreamAudioMemoryLimit) {
  EXPECT_EQ(GetDemuxerStreamAudioMemoryLimit(nullptr),
            internal::kDemuxerStreamAudioMemoryLimitLow);

  AudioDecoderConfig audio_config_opus(
      AudioCodec::kCodecOpus, SampleFormat::kSampleFormatS16,
      ChannelLayout::CHANNEL_LAYOUT_STEREO, 5000 /* samples_per_second */,
      EmptyExtraData(), EncryptionScheme::kUnencrypted);
  EXPECT_EQ(GetDemuxerStreamAudioMemoryLimit(&audio_config_opus),
            internal::kDemuxerStreamAudioMemoryLimitLow);

  AudioDecoderConfig audio_config_ac3(
      AudioCodec::kCodecAC3, SampleFormat::kSampleFormatS16,
      ChannelLayout::CHANNEL_LAYOUT_STEREO, 5000 /* samples_per_second */,
      EmptyExtraData(), EncryptionScheme::kUnencrypted);
  EXPECT_EQ(GetDemuxerStreamAudioMemoryLimit(&audio_config_ac3),
            internal::kDemuxerStreamAudioMemoryLimitMedium);

  AudioDecoderConfig audio_config_aac_1(
      AudioCodec::kCodecAAC, SampleFormat::kSampleFormatS16,
      ChannelLayout::CHANNEL_LAYOUT_5_0, 5000 /* samples_per_second */,
      EmptyExtraData(), EncryptionScheme::kUnencrypted);
  EXPECT_EQ(GetDemuxerStreamAudioMemoryLimit(&audio_config_aac_1),
            internal::kDemuxerStreamAudioMemoryLimitMedium);

  AudioDecoderConfig audio_config_aac_2(
      AudioCodec::kCodecAAC, SampleFormat::kSampleFormatS16,
      ChannelLayout::CHANNEL_LAYOUT_STEREO, 5000 /* samples_per_second */,
      EmptyExtraData(), EncryptionScheme::kUnencrypted);
  EXPECT_EQ(GetDemuxerStreamAudioMemoryLimit(&audio_config_aac_2),
            internal::kDemuxerStreamAudioMemoryLimitLow);
}

TEST(DemuxerMemoryLimitCastTest, GetDemuxerStreamVideoMemoryLimit) {
  EXPECT_EQ(GetDemuxerStreamVideoMemoryLimit(
                Demuxer::DemuxerTypes::kFFmpegDemuxer, nullptr),
            internal::kDemuxerStreamVideoMemoryLimitDefault);
  EXPECT_EQ(GetDemuxerStreamVideoMemoryLimit(
                Demuxer::DemuxerTypes::kChunkDemuxer, nullptr),
            internal::kDemuxerStreamVideoMemoryLimitLow);
  EXPECT_EQ(GetDemuxerStreamVideoMemoryLimit(
                Demuxer::DemuxerTypes::kMediaUrlDemuxer, nullptr),
            internal::kDemuxerStreamVideoMemoryLimitLow);

  VideoDecoderConfig video_config(
      kCodecVP8, VIDEO_CODEC_PROFILE_UNKNOWN,
      VideoDecoderConfig::AlphaMode::kIsOpaque, VideoColorSpace(),
      kNoTransformation, kCodedSize, kVisibleRect, kNaturalSize,
      EmptyExtraData(), EncryptionScheme::kUnencrypted);
  EXPECT_EQ(GetDemuxerStreamVideoMemoryLimit(
                Demuxer::DemuxerTypes::kFFmpegDemuxer, &video_config),
            internal::kDemuxerStreamVideoMemoryLimitDefault);
  EXPECT_EQ(GetDemuxerStreamVideoMemoryLimit(
                Demuxer::DemuxerTypes::kChunkDemuxer, &video_config),
            internal::kDemuxerStreamVideoMemoryLimitLow);
  EXPECT_EQ(GetDemuxerStreamVideoMemoryLimit(
                Demuxer::DemuxerTypes::kMediaUrlDemuxer, &video_config),
            internal::kDemuxerStreamVideoMemoryLimitLow);

  video_config.Initialize(kCodecVP9, VIDEO_CODEC_PROFILE_UNKNOWN,
                          VideoDecoderConfig::AlphaMode::kIsOpaque,
                          VideoColorSpace(), kNoTransformation, kCodedSize,
                          kVisibleRect, kNaturalSize, EmptyExtraData(),
                          EncryptionScheme::kUnencrypted);
  EXPECT_EQ(GetDemuxerStreamVideoMemoryLimit(
                Demuxer::DemuxerTypes::kFFmpegDemuxer, &video_config),
            internal::kDemuxerStreamVideoMemoryLimitDefault);
  EXPECT_EQ(GetDemuxerStreamVideoMemoryLimit(
                Demuxer::DemuxerTypes::kChunkDemuxer, &video_config),
            internal::kDemuxerStreamVideoMemoryLimitMedium);
  EXPECT_EQ(GetDemuxerStreamVideoMemoryLimit(
                Demuxer::DemuxerTypes::kMediaUrlDemuxer, &video_config),
            internal::kDemuxerStreamVideoMemoryLimitLow);
}

TEST(DemuxerMemoryLimitCastTest, GetDemuxerMemoryLimit) {
  EXPECT_EQ(GetDemuxerMemoryLimit(Demuxer::DemuxerTypes::kFFmpegDemuxer),
            internal::kDemuxerStreamAudioMemoryLimitLow +
                internal::kDemuxerStreamVideoMemoryLimitDefault);
  EXPECT_EQ(GetDemuxerMemoryLimit(Demuxer::DemuxerTypes::kChunkDemuxer),
            internal::kDemuxerStreamAudioMemoryLimitLow +
                internal::kDemuxerStreamVideoMemoryLimitLow);
  EXPECT_EQ(GetDemuxerMemoryLimit(Demuxer::DemuxerTypes::kMediaUrlDemuxer),
            internal::kDemuxerStreamAudioMemoryLimitLow +
                internal::kDemuxerStreamVideoMemoryLimitLow);
}

}  // namespace media