summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibAudio/GenericTypes.h
blob: f60bc9af4b1479bab3d34f55d296bf945b571fbc (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
/*
 * Copyright (c) 2022, Lucas Chollet <lucas.chollet@free.fr>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#pragma once

#include <AK/DeprecatedString.h>
#include <AK/Vector.h>

namespace Audio {

// 11.20. PICTURE_TYPE (in Flac specification)
enum class ID3PictureType : u32 {
    Other = 0,
    FileIcon = 1,
    OtherFileIcon = 2,
    FrontCover = 3,
    BackCover = 4,
    LeafletPage = 5,
    Media = 6,
    LeadArtist = 7,
    Artist = 8,
    Conductor = 9,
    Band = 10,
    Composer = 11,
    Lyricist = 12,
    RecordingLocation = 13,
    DuringRecording = 14,
    DuringPerformance = 15,
    MovieScreenCapture = 16,
    BrightColouredFish = 17,
    Illustration = 18,
    BandLogoType = 19,
    PublisherLogoType = 20,
    // others are reserved
};

// Note: This was first implemented for Flac but is compatible with ID3v2
struct PictureData {
    ID3PictureType type {};
    DeprecatedString mime_string {};
    Vector<u32> description_string {};

    u32 width {};
    u32 height {};
    u32 color_depth {};
    u32 colors {};

    Vector<u8> data;
};

// A generic sample seek point within a file.
struct SeekPoint {
    u64 sample_index;
    u64 byte_offset;
};

class SeekTable {
public:
    Optional<SeekPoint const&> seek_point_before(u64 sample_index) const;
    // Returns the distance between the closest two seek points around the sample index.
    // The lower seek point may be exactly at the sample index, but the upper seek point must be after the sample index.
    Optional<u64> seek_point_sample_distance_around(u64 sample_index) const;

    size_t size() const;
    ReadonlySpan<SeekPoint> seek_points() const;

    ErrorOr<void> insert_seek_point(SeekPoint);

private:
    // Invariant: The list of seek points is always sorted.
    // This makes all operations, such as inserting and searching, faster.
    Vector<SeekPoint> m_seek_points;
};

}