m2ts_parser 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e00bcc537869bbb4a999f74764f63818fe65dc16
4
+ data.tar.gz: d6f019b23bd976bd7d038275356ca8dba56cbcf3
5
+ SHA512:
6
+ metadata.gz: b792d452c271706951b0b7cbc9f3ce5df1901800d8d5fd0b3adcf1f4e5511e33cbf091000d9a7fe64d563574159d31a91497707a8839d6154924568d5efeb523
7
+ data.tar.gz: 32b6fd1d026711af47cac4b4e07d18c3a1f7e1be348900298c30e71147c24d6816f1c0a2bbebf795bb6d7564372df193a7dfd56d03695204c35a49231fdf53af
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ *.ts
16
+ *~
17
+ *#
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ruby_m2ts_parser.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 TODO: Write your name
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # Ruby-MPEG2-TS-Parser
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'm2ts_parser'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install m2ts_parser
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/ruby-m2ts-parser/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,23 @@
1
+ module M2TSParser
2
+ module Appendix
3
+ class AribDuration < BinaryParser::TemplateBase
4
+ Def do
5
+ data :hour, BCD, 8
6
+ data :min, BCD, 8
7
+ data :sec, BCD, 8
8
+ end
9
+
10
+ def content_description
11
+ to_s
12
+ end
13
+
14
+ def to_s
15
+ return sprintf("%02d:%02d:%02d", hour.to_i, min.to_i, sec.to_i)
16
+ end
17
+
18
+ def to_sec
19
+ return hour.to_i * 3600 + min.to_i * 60 + sec.to_i
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,27 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ # ARIB-STD-B10 第2部 (v4_9), 付録A 「文字の符号化」に従う定義
4
+ #
5
+ # 番組配列情報の中で使用できる文字および制御コードは、ARIB STD-B24「デジタル放
6
+ # 送におけるデータ符号化方式と伝送方式」に規定される以下のものを使用することとする。
7
+ # ・ 第1編第2部第7章7.1項で規定される8単位文字符号
8
+
9
+ module M2TSParser
10
+ module Appendix
11
+ class ARIBString < BinaryParser::TemplateBase
12
+ require 'tsparser'
13
+ def content_description
14
+ if to_s
15
+ begin
16
+ arib_str = TSparser::AribString.new(TSparser::Binary.new(to_s))
17
+ return arib_str.to_utf_8
18
+ rescue
19
+ return "error"
20
+ end
21
+ else
22
+ return ""
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,46 @@
1
+ require 'date'
2
+ require 'time'
3
+
4
+ module M2TSParser
5
+ module Appendix
6
+ class AribTime < BinaryParser::TemplateBase
7
+ Def do
8
+ data :mjd, UInt, 16
9
+ data :hour, BCD, 8
10
+ data :min, BCD, 8
11
+ data :sec, BCD, 8
12
+ end
13
+
14
+ def date
15
+ return @date ||= convert_mjd_to_date(mjd.to_i)
16
+ end
17
+
18
+ # ARIB STD-B10 2, appendix-C
19
+ def convert_mjd_to_date(mjd)
20
+ y_ = ((mjd - 15078.2) / 365.25).to_i
21
+ m_ = ((mjd - 14956.1 - (y_ * 365.25).to_i) / 30.6001).to_i
22
+ d = mjd - 14956 - (y_ * 365.25).to_i - (m_ * 30.6001).to_i
23
+ k = (m_ == 14 || m_ == 15) ? 1 : 0
24
+ y = y_ + k
25
+ m = m_ - 1 - k * 12
26
+ return Date.new(1900 + y, m, d)
27
+ end
28
+
29
+ def date_str
30
+ return sprintf("%02d/%02d/%02d", date.year, date.month, date.day)
31
+ end
32
+
33
+ def to_s
34
+ return sprintf("%s %02d:%02d:%02d +0900", date_str, hour.to_i, min.to_i, sec.to_i)
35
+ end
36
+
37
+ def to_time
38
+ return Time.parse(to_s)
39
+ end
40
+
41
+ def content_description
42
+ to_s
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,34 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ # ARIB-STD-B10 第2部 (v4_9), 付録M 「限定受信方式識別の割当状況」に従う定義
4
+
5
+ module M2TSParser
6
+ module Appendix
7
+ class CASystemId < BinaryParser::TemplateBase
8
+
9
+ # 限定受信方式識別の割当状況
10
+ ASSIGNMENT = {
11
+ 0x0001 => ["スカパー限定受信方式", "スカパーJSAT独自規定"],
12
+ 0x0003 => ["日立方式", "JCL SPEC-005*1"],
13
+ 0x0004 => ["Secure Navi方式", "JCL SPEC-005*1"],
14
+ 0x0005 => ["ARIB限定受信方式", "ARIB TR-B14, B15"],
15
+ 0x0006 => ["松下CATV限定受信方式", "JCL SPEC-005*1"],
16
+ 0x0007 => ["ケーブルラボ視聴制御方式", "JCL SPEC-001-01*1, JCL SPEC-002*1, JCL SPEC-007*1"],
17
+ 0x0008 => ["u-CAS方式", ""],
18
+ 0x0009 => ["PowerKEY方式", ""],
19
+ 0x000A => ["ARIB限定受信B方式", "ARIB TR-B26"],
20
+ 0x000B => ["パイシス限定受信方式", ""],
21
+ 0x000C => ["MULTI2-NAGRA方式", ""],
22
+ 0x000D => ["IPTVフォーラム・Marlin方式", "IPTV規定 IP放送仕様"]
23
+ }
24
+
25
+ def to_s
26
+ ASSIGNMENT[to_i].to_s
27
+ end
28
+
29
+ def content_description
30
+ to_s
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,160 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ # ARIB-STD-B10 第2部 (v4_9), 付録H 「コンテント記述子におけるジャンル指定」に従う定義
4
+
5
+ module M2TSParser
6
+ module Appendix
7
+ ContentNibbleMapping = {
8
+ 0x0 => ["ニュース/報道", {
9
+ 0x0 => "定時・総合",
10
+ 0x1 => "天気",
11
+ 0x2 => "特集・ドキュメント",
12
+ 0x3 => "政治・国会",
13
+ 0x4 => "経済・市況",
14
+ 0x5 => "海外・国際",
15
+ 0x6 => "解説",
16
+ 0x7 => "討論・会談",
17
+ 0x8 => "報道特番",
18
+ 0x9 => "ローカル・地域",
19
+ 0xA => "交通",
20
+ 0xF => "その他",
21
+ }],
22
+
23
+ 0x1 => ["スポーツ", {
24
+ 0x0 => "スポーツニュース",
25
+ 0x1 => "野球",
26
+ 0x2 => "サッカー",
27
+ 0x3 => "ゴルフ",
28
+ 0x4 => "その他の球技",
29
+ 0x5 => "相撲・格闘技",
30
+ 0x6 => "オリンピック・国際大会",
31
+ 0x7 => "マラソン・陸上・水泳",
32
+ 0x8 => "モータースポーツ",
33
+ 0x9 => "マリン・ウィンタースポーツ",
34
+ 0xA => "競馬・公営競技",
35
+ 0xF => "その他",
36
+ }],
37
+
38
+ 0x2 => ["情報/ワイドショー", {
39
+ 0x0 => "芸能・ワイドショー",
40
+ 0x1 => "ファッション",
41
+ 0x2 => "暮らし・住まい",
42
+ 0x3 => "健康・医療",
43
+ 0x4 => "ショッピング・通販",
44
+ 0x5 => "グルメ・料理",
45
+ 0x6 => "イベント",
46
+ 0x7 => "番組紹介・お知らせ",
47
+ 0xF => "その他",
48
+ }],
49
+
50
+ 0x3 => ["ドラマ", {
51
+ 0x0 => "国内ドラマ",
52
+ 0x1 => "海外ドラマ",
53
+ 0x2 => "時代劇",
54
+ 0xF => "その他",
55
+ }],
56
+
57
+ 0x4 => ["音楽", {
58
+ 0x0 => "国内ロック・ポップス",
59
+ 0x1 => "海外ロック・ポップス",
60
+ 0x2 => "クラシック・オペラ",
61
+ 0x3 => "ジャズ・フュージョン",
62
+ 0x4 => "歌謡曲・演歌",
63
+ 0x5 => "ライブ・コンサート",
64
+ 0x6 => "ランキング・リクエスト",
65
+ 0x7 => "カラオケ・のど自慢",
66
+ 0x8 => "民謡・邦楽",
67
+ 0x9 => "童謡・キッズ",
68
+ 0xA => "民族音楽・ワールドミュージック",
69
+ 0xF => "その他",
70
+ }],
71
+
72
+ 0x5 => ["バラエティ", {
73
+ 0x1 => "ゲーム",
74
+ 0x2 => "トークバラエティ",
75
+ 0x3 => "お笑い・コメディ",
76
+ 0x4 => "音楽バラエティ",
77
+ 0x5 => "旅バラエティ",
78
+ 0x6 => "料理バラエティ",
79
+ 0xF => "その他",
80
+ }],
81
+
82
+ 0x6 => ["映画", {
83
+ 0x0 => "洋画",
84
+ 0x1 => "邦画",
85
+ 0x2 => "アニメ",
86
+ 0xF => "その他",
87
+ }],
88
+
89
+ 0x7 => ["アニメ/特撮", {
90
+ 0x0 => "国内アニメ",
91
+ 0x1 => "海外アニメ",
92
+ 0x2 => "特撮",
93
+ 0xF => "その他",
94
+ }],
95
+
96
+ 0x8 => ["ドキュメンタリー/教養", {
97
+ 0x0 => "社会・時事",
98
+ 0x1 => "歴史・紀行",
99
+ 0x2 => "自然・動物・環境",
100
+ 0x3 => "宇宙・科学・医学",
101
+ 0x4 => "カルチャー・伝統文化",
102
+ 0x5 => "文学・文芸",
103
+ 0x6 => "スポーツ",
104
+ 0x7 => "ドキュメンタリー全般",
105
+ 0x8 => "インタビュー・討論",
106
+ 0xF => "その他",
107
+ }],
108
+
109
+ 0x9 => ["劇場/公演", {
110
+ 0x0 => "現代劇・新劇",
111
+ 0x1 => "ミュージカル",
112
+ 0x2 => "ダンス・バレエ",
113
+ 0x3 => "落語・演芸",
114
+ 0x4 => "歌舞伎・古典",
115
+ 0xF => "その他",
116
+ }],
117
+
118
+ 0xA => ["趣味/教育", {
119
+ 0x0 => "旅・釣り・アウトドア",
120
+ 0x1 => "園芸・ペット・手芸",
121
+ 0x2 => "音楽・美術・工芸",
122
+ 0x3 => "囲碁・将棋",
123
+ 0x4 => "麻雀・パチンコ",
124
+ 0x5 => "車・オートバイ",
125
+ 0x6 => "コンピュータ・TVゲーム",
126
+ 0x7 => "会話・語学",
127
+ 0x8 => "幼児・小学生",
128
+ 0x9 => "中学生・高校生",
129
+ 0xA => "大学生・受験",
130
+ 0xB => "生涯教育・資格",
131
+ 0xC => "教育問題",
132
+ 0xF => "その他",
133
+ }],
134
+
135
+ 0xB => ["福祉", {
136
+ 0x0 => "高齢者",
137
+ 0x1 => "障害者",
138
+ 0x2 => "社会福祉",
139
+ 0x3 => "ボランティア",
140
+ 0x4 => "手話",
141
+ 0x5 => "文字(字幕)",
142
+ 0x6 => "音声解説",
143
+ 0xF => "その他",
144
+ }],
145
+
146
+ 0xE => ["拡張", {
147
+ 0x0 => "BS/地上デジタル放送用番組付属情報",
148
+ 0x1 => "広帯域CS デジタル放送用拡張",
149
+ 0x2 => "衛星デジタル音声放送用拡張",
150
+ 0x3 => "サーバー型番組付属情報",
151
+ 0x4 => "IP 放送用番組付属情報",
152
+ }],
153
+
154
+ 0xF => ["その他", {
155
+ 0xF => "その他",
156
+ }],
157
+ }
158
+ ContentNibbleMapping.default = ["", {}]
159
+ end
160
+ end
@@ -0,0 +1,73 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ # ARIB-STD-B10 第2部 (v4_9), 付録B CRCデコーダモデルに従うデコーダ
4
+ # reference: http://web.cse.ohio-state.edu/~cmcurtin/dvd/dvd_play/src/si/crc32.c
5
+
6
+ module M2TSParser
7
+ module Appendix
8
+ module CRC32Decoder
9
+
10
+ CRC32_TABLE =
11
+ [
12
+ 0x00000000, 0x04c11db7, 0x09823b6e, 0x0d4326d9, 0x130476dc, 0x17c56b6b,
13
+ 0x1a864db2, 0x1e475005, 0x2608edb8, 0x22c9f00f, 0x2f8ad6d6, 0x2b4bcb61,
14
+ 0x350c9b64, 0x31cd86d3, 0x3c8ea00a, 0x384fbdbd, 0x4c11db70, 0x48d0c6c7,
15
+ 0x4593e01e, 0x4152fda9, 0x5f15adac, 0x5bd4b01b, 0x569796c2, 0x52568b75,
16
+ 0x6a1936c8, 0x6ed82b7f, 0x639b0da6, 0x675a1011, 0x791d4014, 0x7ddc5da3,
17
+ 0x709f7b7a, 0x745e66cd, 0x9823b6e0, 0x9ce2ab57, 0x91a18d8e, 0x95609039,
18
+ 0x8b27c03c, 0x8fe6dd8b, 0x82a5fb52, 0x8664e6e5, 0xbe2b5b58, 0xbaea46ef,
19
+ 0xb7a96036, 0xb3687d81, 0xad2f2d84, 0xa9ee3033, 0xa4ad16ea, 0xa06c0b5d,
20
+ 0xd4326d90, 0xd0f37027, 0xddb056fe, 0xd9714b49, 0xc7361b4c, 0xc3f706fb,
21
+ 0xceb42022, 0xca753d95, 0xf23a8028, 0xf6fb9d9f, 0xfbb8bb46, 0xff79a6f1,
22
+ 0xe13ef6f4, 0xe5ffeb43, 0xe8bccd9a, 0xec7dd02d, 0x34867077, 0x30476dc0,
23
+ 0x3d044b19, 0x39c556ae, 0x278206ab, 0x23431b1c, 0x2e003dc5, 0x2ac12072,
24
+ 0x128e9dcf, 0x164f8078, 0x1b0ca6a1, 0x1fcdbb16, 0x018aeb13, 0x054bf6a4,
25
+ 0x0808d07d, 0x0cc9cdca, 0x7897ab07, 0x7c56b6b0, 0x71159069, 0x75d48dde,
26
+ 0x6b93dddb, 0x6f52c06c, 0x6211e6b5, 0x66d0fb02, 0x5e9f46bf, 0x5a5e5b08,
27
+ 0x571d7dd1, 0x53dc6066, 0x4d9b3063, 0x495a2dd4, 0x44190b0d, 0x40d816ba,
28
+ 0xaca5c697, 0xa864db20, 0xa527fdf9, 0xa1e6e04e, 0xbfa1b04b, 0xbb60adfc,
29
+ 0xb6238b25, 0xb2e29692, 0x8aad2b2f, 0x8e6c3698, 0x832f1041, 0x87ee0df6,
30
+ 0x99a95df3, 0x9d684044, 0x902b669d, 0x94ea7b2a, 0xe0b41de7, 0xe4750050,
31
+ 0xe9362689, 0xedf73b3e, 0xf3b06b3b, 0xf771768c, 0xfa325055, 0xfef34de2,
32
+ 0xc6bcf05f, 0xc27dede8, 0xcf3ecb31, 0xcbffd686, 0xd5b88683, 0xd1799b34,
33
+ 0xdc3abded, 0xd8fba05a, 0x690ce0ee, 0x6dcdfd59, 0x608edb80, 0x644fc637,
34
+ 0x7a089632, 0x7ec98b85, 0x738aad5c, 0x774bb0eb, 0x4f040d56, 0x4bc510e1,
35
+ 0x46863638, 0x42472b8f, 0x5c007b8a, 0x58c1663d, 0x558240e4, 0x51435d53,
36
+ 0x251d3b9e, 0x21dc2629, 0x2c9f00f0, 0x285e1d47, 0x36194d42, 0x32d850f5,
37
+ 0x3f9b762c, 0x3b5a6b9b, 0x0315d626, 0x07d4cb91, 0x0a97ed48, 0x0e56f0ff,
38
+ 0x1011a0fa, 0x14d0bd4d, 0x19939b94, 0x1d528623, 0xf12f560e, 0xf5ee4bb9,
39
+ 0xf8ad6d60, 0xfc6c70d7, 0xe22b20d2, 0xe6ea3d65, 0xeba91bbc, 0xef68060b,
40
+ 0xd727bbb6, 0xd3e6a601, 0xdea580d8, 0xda649d6f, 0xc423cd6a, 0xc0e2d0dd,
41
+ 0xcda1f604, 0xc960ebb3, 0xbd3e8d7e, 0xb9ff90c9, 0xb4bcb610, 0xb07daba7,
42
+ 0xae3afba2, 0xaafbe615, 0xa7b8c0cc, 0xa379dd7b, 0x9b3660c6, 0x9ff77d71,
43
+ 0x92b45ba8, 0x9675461f, 0x8832161a, 0x8cf30bad, 0x81b02d74, 0x857130c3,
44
+ 0x5d8a9099, 0x594b8d2e, 0x5408abf7, 0x50c9b640, 0x4e8ee645, 0x4a4ffbf2,
45
+ 0x470cdd2b, 0x43cdc09c, 0x7b827d21, 0x7f436096, 0x7200464f, 0x76c15bf8,
46
+ 0x68860bfd, 0x6c47164a, 0x61043093, 0x65c52d24, 0x119b4be9, 0x155a565e,
47
+ 0x18197087, 0x1cd86d30, 0x029f3d35, 0x065e2082, 0x0b1d065b, 0x0fdc1bec,
48
+ 0x3793a651, 0x3352bbe6, 0x3e119d3f, 0x3ad08088, 0x2497d08d, 0x2056cd3a,
49
+ 0x2d15ebe3, 0x29d4f654, 0xc5a92679, 0xc1683bce, 0xcc2b1d17, 0xc8ea00a0,
50
+ 0xd6ad50a5, 0xd26c4d12, 0xdf2f6bcb, 0xdbee767c, 0xe3a1cbc1, 0xe760d676,
51
+ 0xea23f0af, 0xeee2ed18, 0xf0a5bd1d, 0xf464a0aa, 0xf9278673, 0xfde69bc4,
52
+ 0x89b8fd09, 0x8d79e0be, 0x803ac667, 0x84fbdbd0, 0x9abc8bd5, 0x9e7d9662,
53
+ 0x933eb0bb, 0x97ffad0c, 0xafb010b1, 0xab710d06, 0xa6322bdf, 0xa2f33668,
54
+ 0xbcb4666d, 0xb8757bda, 0xb5365d03, 0xb1f740b4
55
+ ]
56
+
57
+ def calc_crc32(bytes, length)
58
+ crc = 0xffffffff
59
+ length.times do |i|
60
+ crc = ((crc << 8) & 0xffffffff) ^ CRC32_TABLE[((crc >> 24) ^ bytes[i]) & 0xff]
61
+ end
62
+ return crc
63
+ end
64
+
65
+ def check_crc32
66
+ if structure_bit_length % 8 != 0
67
+ raise "binary's length should be multiple of 8bit to check CRC32."
68
+ end
69
+ return calc_crc32(to_chars, structure_bit_length / 8) == 0
70
+ end
71
+ end
72
+ end
73
+ end