Move JpegParser into a new //media/parsers folder.

6dc43e3e4dca923fa5afa970965c107923af5c53 incorrectly created a
component within //media/filters that can't take a //media DEP.
To avoid fragile build issues such components should be in their
own folders with clear assert_no_deps in place.

This breaks the implicit dependency to //media to encourage users
to take the DEP directly if needed (in the few locations needed now).

BUG=none
TEST=compiles
R=mcasas, piman

Change-Id: Ic37d896808c41534e9d66357cedbd1cc9f5b1009
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1616980
Auto-Submit: Dale Curtis <dalecurtis@chromium.org>
Reviewed-by: Antoine Labour <piman@chromium.org>
Reviewed-by: Miguel Casas <mcasas@chromium.org>
Commit-Queue: Miguel Casas <mcasas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#661403}
diff --git a/components/chromeos_camera/BUILD.gn b/components/chromeos_camera/BUILD.gn
index 7c1f094..a60b8e2fc 100644
--- a/components/chromeos_camera/BUILD.gn
+++ b/components/chromeos_camera/BUILD.gn
@@ -144,6 +144,7 @@
       "//media:test_support",
       "//media/gpu:buildflags",
       "//media/gpu/test:helpers",
+      "//media/parsers",
       "//mojo/core/embedder",
       "//testing/gtest",
       "//third_party:jpeg",
@@ -179,6 +180,7 @@
     "//media:test_support",
     "//media/gpu:buildflags",
     "//media/gpu/test:helpers",
+    "//media/parsers",
     "//mojo/core/embedder",
     "//testing/gtest",
     "//third_party/libyuv",
diff --git a/components/chromeos_camera/jpeg_encode_accelerator_unittest.cc b/components/chromeos_camera/jpeg_encode_accelerator_unittest.cc
index 83c353c..cea3b569 100644
--- a/components/chromeos_camera/jpeg_encode_accelerator_unittest.cc
+++ b/components/chromeos_camera/jpeg_encode_accelerator_unittest.cc
@@ -26,9 +26,9 @@
 #include "components/chromeos_camera/gpu_jpeg_encode_accelerator_factory.h"
 #include "components/chromeos_camera/jpeg_encode_accelerator.h"
 #include "media/base/test_data_util.h"
-#include "media/filters/jpeg_parser.h"
 #include "media/gpu/buildflags.h"
 #include "media/gpu/test/video_accelerator_unittest_helpers.h"
+#include "media/parsers/jpeg_parser.h"
 #include "mojo/core/embedder/embedder.h"
 #include "testing/gtest/include/gtest/gtest.h"
 #include "third_party/libyuv/include/libyuv.h"
diff --git a/components/chromeos_camera/mjpeg_decode_accelerator_unittest.cc b/components/chromeos_camera/mjpeg_decode_accelerator_unittest.cc
index 11d431f..3490cb7 100644
--- a/components/chromeos_camera/mjpeg_decode_accelerator_unittest.cc
+++ b/components/chromeos_camera/mjpeg_decode_accelerator_unittest.cc
@@ -26,9 +26,9 @@
 #include "components/chromeos_camera/gpu_mjpeg_decode_accelerator_factory.h"
 #include "components/chromeos_camera/mjpeg_decode_accelerator.h"
 #include "media/base/test_data_util.h"
-#include "media/filters/jpeg_parser.h"
 #include "media/gpu/buildflags.h"
 #include "media/gpu/test/video_accelerator_unittest_helpers.h"
+#include "media/parsers/jpeg_parser.h"
 #include "mojo/core/embedder/embedder.h"
 #include "testing/gtest/include/gtest/gtest.h"
 #include "third_party/libyuv/include/libyuv.h"
diff --git a/gpu/ipc/client/BUILD.gn b/gpu/ipc/client/BUILD.gn
index 5a9ee4b..ad92416 100644
--- a/gpu/ipc/client/BUILD.gn
+++ b/gpu/ipc/client/BUILD.gn
@@ -37,7 +37,7 @@
     "//gpu/command_buffer/common:common_sources",
     "//gpu/config:config_sources",
     "//gpu/ipc/common:ipc_common_sources",
-    "//media/filters:jpeg_parser",
+    "//media/parsers",
     "//mojo/public/cpp/system",
     "//ui/gfx:color_space",
     "//ui/gfx/geometry",
diff --git a/gpu/ipc/client/DEPS b/gpu/ipc/client/DEPS
index 7a79c6ac..88b89ed 100644
--- a/gpu/ipc/client/DEPS
+++ b/gpu/ipc/client/DEPS
@@ -11,7 +11,7 @@
     "+components/viz/test/test_gpu_memory_buffer_manager.h",
   ],
   "image_decode_accelerator_proxy.cc": [
-    "+media/filters/jpeg_parser.h",
+    "+media/parsers/jpeg_parser.h",
   ],
   "raster_in_process_context_tests.cc": [
     "+components/viz/common/resources/resource_format.h",
diff --git a/gpu/ipc/client/image_decode_accelerator_proxy.cc b/gpu/ipc/client/image_decode_accelerator_proxy.cc
index ef7442f..098a2cf 100644
--- a/gpu/ipc/client/image_decode_accelerator_proxy.cc
+++ b/gpu/ipc/client/image_decode_accelerator_proxy.cc
@@ -17,7 +17,7 @@
 #include "gpu/ipc/client/gpu_channel_host.h"
 #include "gpu/ipc/common/command_buffer_id.h"
 #include "gpu/ipc/common/gpu_messages.h"
-#include "media/filters/jpeg_parser.h"
+#include "media/parsers/jpeg_parser.h"
 #include "ui/gfx/color_space.h"
 #include "ui/gfx/geometry/size.h"
 
diff --git a/media/BUILD.gn b/media/BUILD.gn
index f9ae1d9..125c6d6 100644
--- a/media/BUILD.gn
+++ b/media/BUILD.gn
@@ -149,6 +149,7 @@
     "//media/learning:unit_tests",
     "//media/mojo:unit_tests",
     "//media/muxers:unit_tests",
+    "//media/parsers:unit_tests",
     "//media/renderers:unit_tests",
     "//media/test:pipeline_integration_tests",
     "//media/test:run_all_unittests",
@@ -314,18 +315,6 @@
   }
 }
 
-fuzzer_test("media_jpeg_parser_picture_fuzzer") {
-  sources = [
-    "filters/jpeg_parser_picture_fuzzertest.cc",
-  ]
-  deps = [
-    ":test_support",
-    "//base",
-  ]
-  seed_corpus = "test/data"
-  dict = "test/jpeg.dict"
-}
-
 fuzzer_test("media_vp8_parser_fuzzer") {
   sources = [
     "filters/vp8_parser_fuzzertest.cc",
diff --git a/media/capture/BUILD.gn b/media/capture/BUILD.gn
index c5c9c5d..6b12ed4 100644
--- a/media/capture/BUILD.gn
+++ b/media/capture/BUILD.gn
@@ -86,6 +86,7 @@
     "//media/capture/mojom:image_capture",
     "//media/capture/mojom:image_capture_types",
     "//media/mojo/interfaces:interfaces",
+    "//media/parsers",
     "//third_party/libyuv",
     "//ui/gfx",
   ]
diff --git a/media/capture/video/file_video_capture_device.cc b/media/capture/video/file_video_capture_device.cc
index 06f4527..18d506a 100644
--- a/media/capture/video/file_video_capture_device.cc
+++ b/media/capture/video/file_video_capture_device.cc
@@ -18,7 +18,7 @@
 #include "media/capture/mojom/image_capture_types.h"
 #include "media/capture/video/blob_utils.h"
 #include "media/capture/video_capture_types.h"
-#include "media/filters/jpeg_parser.h"
+#include "media/parsers/jpeg_parser.h"
 
 namespace media {
 
diff --git a/media/filters/BUILD.gn b/media/filters/BUILD.gn
index 1324da9..eec20a7 100644
--- a/media/filters/BUILD.gn
+++ b/media/filters/BUILD.gn
@@ -89,10 +89,6 @@
     "//media:subcomponent_config",
   ]
 
-  public_deps = [
-    ":jpeg_parser",
-  ]
-
   deps = [
     "//cc/base",  # For MathUtil.
     "//gpu/command_buffer/common",
@@ -226,34 +222,6 @@
   }
 }
 
-# This component allows other targets to use the JPEG parser as a standalone,
-# general-purpose utility without having to pull all of //media as a dependency
-# (which could potentially result in cycles).
-component("jpeg_parser") {
-  output_name = "media_filters_jpeg_parser"
-  sources = [
-    "jpeg_parser.cc",
-    "jpeg_parser.h",
-  ]
-  defines = [ "IS_JPEG_PARSER_IMPL" ]
-  deps = [
-    "//base",
-  ]
-}
-
-source_set("jpeg_parser_unit_tests") {
-  testonly = true
-  sources = [
-    "jpeg_parser_unittest.cc",
-  ]
-  deps = [
-    ":jpeg_parser",
-    "//base",
-    "//media:test_support",
-    "//testing/gtest",
-  ]
-}
-
 source_set("perftests") {
   testonly = true
   sources = []
@@ -328,7 +296,6 @@
   ]
 
   deps = [
-    ":jpeg_parser_unit_tests",
     "//base/test:test_support",
     "//media:test_support",
     "//testing/gmock",
diff --git a/media/gpu/v4l2/BUILD.gn b/media/gpu/v4l2/BUILD.gn
index 03fcb34..d756ef22 100644
--- a/media/gpu/v4l2/BUILD.gn
+++ b/media/gpu/v4l2/BUILD.gn
@@ -91,6 +91,7 @@
     deps += [
       "//components/chromeos_camera:jpeg_encode_accelerator",
       "//components/chromeos_camera:mjpeg_decode_accelerator",
+      "//media/parsers",
     ]
   }
 }
diff --git a/media/gpu/v4l2/v4l2_jpeg_encode_accelerator.h b/media/gpu/v4l2/v4l2_jpeg_encode_accelerator.h
index c337ec6..cc73b5c 100644
--- a/media/gpu/v4l2/v4l2_jpeg_encode_accelerator.h
+++ b/media/gpu/v4l2/v4l2_jpeg_encode_accelerator.h
@@ -21,9 +21,9 @@
 #include "media/base/bitstream_buffer.h"
 #include "media/base/unaligned_shared_memory.h"
 #include "media/base/video_frame.h"
-#include "media/filters/jpeg_parser.h"
 #include "media/gpu/media_gpu_export.h"
 #include "media/gpu/v4l2/v4l2_device.h"
+#include "media/parsers/jpeg_parser.h"
 
 namespace {
 
diff --git a/media/gpu/v4l2/v4l2_mjpeg_decode_accelerator.cc b/media/gpu/v4l2/v4l2_mjpeg_decode_accelerator.cc
index 8aea744..d1f4194 100644
--- a/media/gpu/v4l2/v4l2_mjpeg_decode_accelerator.cc
+++ b/media/gpu/v4l2/v4l2_mjpeg_decode_accelerator.cc
@@ -16,8 +16,8 @@
 #include "base/numerics/safe_conversions.h"
 #include "base/stl_util.h"
 #include "base/threading/thread_task_runner_handle.h"
-#include "media/filters/jpeg_parser.h"
 #include "media/gpu/macros.h"
+#include "media/parsers/jpeg_parser.h"
 #include "third_party/libyuv/include/libyuv.h"
 
 #define IOCTL_OR_ERROR_RETURN_VALUE(type, arg, value, type_name)    \
diff --git a/media/gpu/vaapi/BUILD.gn b/media/gpu/vaapi/BUILD.gn
index ab95283..3ed99a13 100644
--- a/media/gpu/vaapi/BUILD.gn
+++ b/media/gpu/vaapi/BUILD.gn
@@ -94,6 +94,7 @@
     deps += [
       "//components/chromeos_camera:jpeg_encode_accelerator",
       "//components/chromeos_camera:mjpeg_decode_accelerator",
+      "//media/parsers",
     ]
   }
 
@@ -160,6 +161,7 @@
     ":vaapi_utils_unittest",
     "//base",
     "//media:test_support",
+    "//media/parsers",
     "//skia",
     "//testing/gtest",
     "//third_party/libyuv:libyuv",
diff --git a/media/gpu/vaapi/vaapi_jpeg_decoder.cc b/media/gpu/vaapi/vaapi_jpeg_decoder.cc
index 4fe9560..364a874f 100644
--- a/media/gpu/vaapi/vaapi_jpeg_decoder.cc
+++ b/media/gpu/vaapi/vaapi_jpeg_decoder.cc
@@ -17,11 +17,11 @@
 #include "base/numerics/safe_conversions.h"
 #include "base/stl_util.h"
 #include "media/base/video_types.h"
-#include "media/filters/jpeg_parser.h"
 #include "media/gpu/macros.h"
 #include "media/gpu/vaapi/va_surface.h"
 #include "media/gpu/vaapi/vaapi_utils.h"
 #include "media/gpu/vaapi/vaapi_wrapper.h"
+#include "media/parsers/jpeg_parser.h"
 
 namespace media {
 
diff --git a/media/gpu/vaapi/vaapi_jpeg_decoder_unittest.cc b/media/gpu/vaapi/vaapi_jpeg_decoder_unittest.cc
index 14304a7..9a5b262 100644
--- a/media/gpu/vaapi/vaapi_jpeg_decoder_unittest.cc
+++ b/media/gpu/vaapi/vaapi_jpeg_decoder_unittest.cc
@@ -26,10 +26,10 @@
 #include "base/strings/string_util.h"
 #include "media/base/test_data_util.h"
 #include "media/base/video_types.h"
-#include "media/filters/jpeg_parser.h"
 #include "media/gpu/vaapi/vaapi_jpeg_decoder.h"
 #include "media/gpu/vaapi/vaapi_utils.h"
 #include "media/gpu/vaapi/vaapi_wrapper.h"
+#include "media/parsers/jpeg_parser.h"
 #include "third_party/libyuv/include/libyuv.h"
 #include "third_party/skia/include/core/SkColor.h"
 #include "third_party/skia/include/core/SkImageInfo.h"
diff --git a/media/gpu/vaapi/vaapi_jpeg_encode_accelerator.cc b/media/gpu/vaapi/vaapi_jpeg_encode_accelerator.cc
index ad547de..fe2fb53 100644
--- a/media/gpu/vaapi/vaapi_jpeg_encode_accelerator.cc
+++ b/media/gpu/vaapi/vaapi_jpeg_encode_accelerator.cc
@@ -18,9 +18,9 @@
 #include "base/trace_event/trace_event.h"
 #include "media/base/bind_to_current_loop.h"
 #include "media/base/video_frame.h"
-#include "media/filters/jpeg_parser.h"
 #include "media/gpu/macros.h"
 #include "media/gpu/vaapi/vaapi_jpeg_encoder.h"
+#include "media/parsers/jpeg_parser.h"
 
 namespace media {
 
diff --git a/media/gpu/vaapi/vaapi_jpeg_encoder.cc b/media/gpu/vaapi/vaapi_jpeg_encoder.cc
index e4bd4f1..ebfaa37 100644
--- a/media/gpu/vaapi/vaapi_jpeg_encoder.cc
+++ b/media/gpu/vaapi/vaapi_jpeg_encoder.cc
@@ -13,9 +13,9 @@
 #include "base/logging.h"
 #include "base/numerics/safe_conversions.h"
 #include "base/stl_util.h"
-#include "media/filters/jpeg_parser.h"
 #include "media/gpu/macros.h"
 #include "media/gpu/vaapi/vaapi_wrapper.h"
+#include "media/parsers/jpeg_parser.h"
 
 namespace media {
 
diff --git a/media/parsers/BUILD.gn b/media/parsers/BUILD.gn
new file mode 100644
index 0000000..4b2fab19
--- /dev/null
+++ b/media/parsers/BUILD.gn
@@ -0,0 +1,48 @@
+# Copyright 2019 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.
+
+import("//media/media_options.gni")
+
+component("parsers") {
+  sources = [
+    "jpeg_parser.cc",
+    "jpeg_parser.h",
+    "media_parsers_export.h",
+  ]
+  defines = [ "IS_MEDIA_PARSER_IMPL" ]
+  deps = [
+    "//base",
+  ]
+
+  # This target is used in GPU IPC code and cannot depend on any //media code.
+  assert_no_deps = [
+    "//media",
+    "//media:shared_memory_support",
+  ]
+}
+
+source_set("unit_tests") {
+  testonly = true
+  sources = [
+    "jpeg_parser_unittest.cc",
+  ]
+  deps = [
+    ":parsers",
+    "//base",
+    "//media:test_support",
+    "//testing/gtest",
+  ]
+}
+
+fuzzer_test("media_jpeg_parser_picture_fuzzer") {
+  sources = [
+    "jpeg_parser_picture_fuzzertest.cc",
+  ]
+  deps = [
+    ":parsers",
+    "//base",
+  ]
+  seed_corpus = "//media/test/data"
+  dict = "//media/test/jpeg.dict"
+}
diff --git a/media/filters/jpeg_parser.cc b/media/parsers/jpeg_parser.cc
similarity index 99%
rename from media/filters/jpeg_parser.cc
rename to media/parsers/jpeg_parser.cc
index e2b94321..344f7c3 100644
--- a/media/filters/jpeg_parser.cc
+++ b/media/parsers/jpeg_parser.cc
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#include "media/filters/jpeg_parser.h"
+#include "media/parsers/jpeg_parser.h"
 
 #include "base/big_endian.h"
 #include "base/logging.h"
diff --git a/media/filters/jpeg_parser.h b/media/parsers/jpeg_parser.h
similarity index 93%
rename from media/filters/jpeg_parser.h
rename to media/parsers/jpeg_parser.h
index 0717756..faab7e92 100644
--- a/media/filters/jpeg_parser.h
+++ b/media/parsers/jpeg_parser.h
@@ -2,13 +2,13 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 //
-#ifndef MEDIA_FILTERS_JPEG_PARSER_H_
-#define MEDIA_FILTERS_JPEG_PARSER_H_
+#ifndef MEDIA_PARSERS_JPEG_PARSER_H_
+#define MEDIA_PARSERS_JPEG_PARSER_H_
 
 #include <stddef.h>
 #include <stdint.h>
 
-#include "base/component_export.h"
+#include "media/parsers/media_parsers_export.h"
 
 namespace media {
 
@@ -81,11 +81,11 @@
 };
 
 // K.3.3.1 "Specification of typical tables for DC difference coding"
-COMPONENT_EXPORT(JPEG_PARSER)
+MEDIA_PARSERS_EXPORT
 extern const JpegHuffmanTable kDefaultDcTable[kJpegMaxHuffmanTableNumBaseline];
 
 // K.3.3.2 "Specification of typical tables for AC coefficient coding"
-COMPONENT_EXPORT(JPEG_PARSER)
+MEDIA_PARSERS_EXPORT
 extern const JpegHuffmanTable kDefaultAcTable[kJpegMaxHuffmanTableNumBaseline];
 
 // Parsing result of JPEG DQT marker.
@@ -94,11 +94,11 @@
   uint8_t value[kDctSize];  // baseline only supports 8 bits quantization table
 };
 
-COMPONENT_EXPORT(JPEG_PARSER) extern const uint8_t kZigZag8x8[64];
+MEDIA_PARSERS_EXPORT extern const uint8_t kZigZag8x8[64];
 
 // Table K.1 Luminance quantization table
 // Table K.2 Chrominance quantization table
-COMPONENT_EXPORT(JPEG_PARSER)
+MEDIA_PARSERS_EXPORT
 extern const JpegQuantizationTable kDefaultQuantTable[2];
 
 // Parsing result of a JPEG component.
@@ -146,7 +146,7 @@
 // Parses JPEG picture in |buffer| with |length|.  Returns true iff header is
 // valid and JPEG baseline sequential process is present. If parsed
 // successfully, |result| is the parsed result.
-COMPONENT_EXPORT(JPEG_PARSER)
+MEDIA_PARSERS_EXPORT
 bool ParseJpegPicture(const uint8_t* buffer,
                       size_t length,
                       JpegParseResult* result);
@@ -154,11 +154,11 @@
 // Parses the first image of JPEG stream in |buffer| with |length|.  Returns
 // true iff header is valid and JPEG baseline sequential process is present.
 // If parsed successfully, |result| is the parsed result.
-COMPONENT_EXPORT(JPEG_PARSER)
+MEDIA_PARSERS_EXPORT
 bool ParseJpegStream(const uint8_t* buffer,
                      size_t length,
                      JpegParseResult* result);
 
 }  // namespace media
 
-#endif  // MEDIA_FILTERS_JPEG_PARSER_H_
+#endif  // MEDIA_PARSERS_JPEG_PARSER_H_
diff --git a/media/filters/jpeg_parser_picture_fuzzertest.cc b/media/parsers/jpeg_parser_picture_fuzzertest.cc
similarity index 93%
rename from media/filters/jpeg_parser_picture_fuzzertest.cc
rename to media/parsers/jpeg_parser_picture_fuzzertest.cc
index d41fcb6..31d9cae 100644
--- a/media/filters/jpeg_parser_picture_fuzzertest.cc
+++ b/media/parsers/jpeg_parser_picture_fuzzertest.cc
@@ -6,7 +6,7 @@
 #include <stdint.h>
 
 #include "base/logging.h"
-#include "media/filters/jpeg_parser.h"
+#include "media/parsers/jpeg_parser.h"
 
 struct Environment {
   Environment() { logging::SetMinLogLevel(logging::LOG_FATAL); }
diff --git a/media/filters/jpeg_parser_unittest.cc b/media/parsers/jpeg_parser_unittest.cc
similarity index 98%
rename from media/filters/jpeg_parser_unittest.cc
rename to media/parsers/jpeg_parser_unittest.cc
index b29ebad..72b9ae9 100644
--- a/media/filters/jpeg_parser_unittest.cc
+++ b/media/parsers/jpeg_parser_unittest.cc
@@ -8,7 +8,7 @@
 #include "base/files/memory_mapped_file.h"
 #include "base/path_service.h"
 #include "media/base/test_data_util.h"
-#include "media/filters/jpeg_parser.h"
+#include "media/parsers/jpeg_parser.h"
 #include "testing/gtest/include/gtest/gtest.h"
 
 namespace media {
diff --git a/media/parsers/media_parsers_export.h b/media/parsers/media_parsers_export.h
new file mode 100644
index 0000000..72277ea
--- /dev/null
+++ b/media/parsers/media_parsers_export.h
@@ -0,0 +1,12 @@
+// Copyright 2019 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.
+
+#ifndef MEDIA_PARSERS_MEDIA_PARSERS_EXPORT_H_
+#define MEDIA_PARSERS_MEDIA_PARSERS_EXPORT_H_
+
+#include "base/component_export.h"
+
+#define MEDIA_PARSERS_EXPORT COMPONENT_EXPORT(MEDIA_PARSER)
+
+#endif  // MEDIA_PARSERS_MEDIA_PARSERS_EXPORT_H_